﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
using System.Transactions;
using System.Threading;
using System.Net;
using System.Data.Entity.Validation;
using System.Data.Entity.Infrastructure;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;

namespace BLLA
{
    public partial class Order_Form_T : BaseBLL<Model.Order_Form_T>, IBLL.IOrder_Form_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();

        public string CountPs(string MerId, string StatS, string BDate, string EDate, string YZM, int RETID)
        {


            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT * FROM View_Order_Form where FormMerID='" + MerId + "'  AND IsPay=2 ");
                if (BDate != "")
                {
                    sql.Append(" AND FormTime >'" + BDate + "000000'");
                }
                if (EDate != "")
                {
                    sql.Append(" AND FormTime <'" + EDate + "235959'");
                }
                string[] sts = StatS.Split(',');
                List<Model.Order_FormControl_T> ConList = base.DBSession.IOrder_FormControl_TDAL.GetListBy(u => true);
                List<Model.PsBB> PsList = new List<PsBB>();
                int total = 0;
                for (int i = 0; i < sts.Length; i++)
                {
                    List<Model.View_Order_Form> Lst = base.DBSession.IView_Order_FormDAL.GetListBy(sql.ToString() + " AND FormBY='" + sts[i] + "'");
                    PsBB np = new PsBB();
                    np.CountForm = Lst.Count;
                    np.Stat = sts[i];
                    try
                    {
                        np.StatName = (from m in ConList where m.ConID == sts[i] select m.ConText).First();
                    }
                    catch (Exception)
                    {

                    }
                    np.Count = 0;
                    foreach (var item in Lst)
                    {
                        np.Count += item.DelFormMon;
                    }
                    PsList.Add(np);
                    total += np.Count;
                }
                result.total = total;
                result.rows = PsList;
                result.BS = "1";
                result.Msg = "查询成功";

            }
            catch (Exception ex)
            {
                WriteLog.WriteW("CountPs异常：" + ex.Message);
                result.BS = "-99";
                result.Msg = "更新失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }

        #region 修改商户的订单状态和备注信息
        /// <summary>
        /// 修改商户的订单状态和备注信息
        /// </summary>
        /// <param name="OperID">操作员ID</param>
        /// <param name="MerID">商户ID</param>
        /// <param name="FormID">订单ID</param>
        /// <param name="FormBY">订单状态</param>
        /// <param name="IntBZ">备注</param>
        /// <param name="YZM">验证码</param> 
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string SetOrder_Form(int OperID, int MerID, string FormID, string FormBY, string IntBZ, string YZM, int RETID)
        {
            Help.Log.Debug("SetOrder_Form", "0");
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                int Foid = int.Parse(FormID);//转换订单ID

                int fm = int.Parse(FormID);

                //List<Model.Order_Form_T> list_info = base.GetListBy(u => u.FormID == Foid);
                List<Model.Order_Form_T> list_info = base.DBSession.IOrder_Form_TDAL.GetListBy("select * from Order_Form_T where FormID=" + FormID);

                Help.Log.Debug("SetOrder_Form ", "    1");
                if (list_info == null || list_info.Count <= 0)
                {
                    WriteLog.WriteW("修改商户的订单状态和备注信息");
                    result.BS = "-1";
                    result.Msg = "更新失败";
                    return os.StringOfObject(result, RETID);
                }
                Help.Log.Debug("SetOrder_Form ", "    2");
                Model.Order_Form_T tmplinfo = list_info.First();
                Model.Order_Form_T info = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormID == Foid).First();
                Help.FuZhi<Model.Order_Form_T>.FZ(ref info, tmplinfo);
                string oldfrmby = info.FormBY;
                Help.Log.Debug("SetOrder_Form", "未更改: SetOrder_Form   FormID=" + info.FormID + "   FormBY=" + info.FormBY + "   IsPay=" + info.IsPay);
                string T = "";
                int ret = -1;
                T = "修改";
                info.LastTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                info.FormBY = FormBY;
                info.IntBZ = IntBZ;
                if (info.IsPay != 2)
                {
                    Help.Log.Debug("SetOrder_Form", "发现没给钱: SetOrder_Form   FormID=" + info.FormID + "   FormBY=" + info.FormBY + "   IsPay=" + info.IsPay);
                    if (info.FormPayType == 1)
                    {
                        try
                        {

                            if (base.DBSession.IOrder_FlowMon_TDAL.GetListBy(u => u.OrdrID == info.FormID & u.WaltFlowType == "1A0002").Count > 0)
                            {
                                info.IsPay = 2;
                            }

                        }
                        catch (Exception ex)
                        {
                            Help.Log.Debug("SetOrder_Form发现没给钱异常FormPayType == 1", ex.Message);
                        }

                    }
                    if (info.FormPayType == 2)
                    {
                        try
                        {
                            string orid = info.FormID + "";

                            if (base.DBSession.IOrder_FlowPay_TDAL.GetListBy(u => u.OrdrID == orid).Count > 0)
                            {
                                info.IsPay = 2;
                            }

                        }
                        catch (Exception ex)
                        {
                            Help.Log.Debug("SetOrder_Form发现没给钱异常FormPayType == 2", ex.Message);
                        }

                    }
                    info.IsPay = 2;
                }
                Help.Log.Debug("SetOrder_Form   ", "  3");
                try
                {

                    ret = base.Modify(info);
                }
                catch (Exception ex)
                {
                    Help.Log.Debug("SetOrder_Form    ", "  Modify   " + ex.Message);
                }
                WriteLog.WriteW("SetOrder_Form     4");
                if (ret > 0)
                {


                    Model.Order_FormLog fl = new Model.Order_FormLog();
                    //OperaType  0:用户ID  1：OperID 2：派送员ID
                    fl.OperaType = 1;
                    fl.BZ = IntBZ;
                    fl.FormId = int.Parse(FormID);
                    fl.FormStat = FormBY;
                    fl.OpearDateTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
                    fl.OperaId = OperID;
                    Help.Log.Debug("SetOrder_Form   ", "  5");
                    base.DBSession.IOrder_FormLogDAL.Add(fl);
                    Help.Log.Debug("SetOrder_Form  ", "   6");

                    // 将操作记录到日志表中
                    Model.Order_OperationFlow_T Log = new Model.Order_OperationFlow_T();
                    Log.OperationTitle = "修改商户的订单状态和备注信息";
                    Log.OperationText = T + "商户的订单状态和备注信息成功";
                    Log.OperationType = "1F0006";
                    Log.OperationRes = "成功";
                    Log.OperationUser = OperID;
                    string str_log = os.StringOfObject(Log, RETID);
                    Help.Log.Debug("SetOrder_Form    ", " 7");
                    bool isSuccess = new Order_OperationFlow_T().AddOrder_OperationFlow(str_log, RETID);
                    Help.Log.Debug("SetOrder_Form ", "    8");
                    if (!isSuccess)
                    {
                        WriteLog.WriteW("新增系统操作流水失败");
                    }

                    #region 微信通知调度员

                    if (FormBY == "1A04")
                    {


                        //List<Model.Order_FormControl_T> frmCrlList = base.DBSession.IOrder_FormControl_TDAL.GetListBy("select * from  Order_FormControl_T where  ConID='" + FormBY + "'");
                        // Help.Log.Debug("SetOrder_Form  ", "   9");
                        // Model.Order_FormControl_T frmCtrl = new Model.Order_FormControl_T();
                        //if (frmCrlList != null && frmCrlList.Count > 0)
                        // {
                        //  frmCtrl = frmCrlList.First();
                        //string[] coms = frmCtrl.ComponenGroup.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        //foreach (var item in coms)
                        //{
                        //  if (item.Trim() == "012002")
                        //{
                        //List<Model.Order_FormControl_T> odCrlList = base.DBSession.IOrder_FormControl_TDAL.GetListBy("select * from  Order_FormControl_T where  ConID='" + oldfrmby + "'");//u => u.ConID == oldfrmby);
                        //Help.Log.Debug("SetOrder_Form  ", "   10");
                        //Model.Order_FormControl_T odCrl = new Model.Order_FormControl_T();

                        //if (odCrlList != null && odCrlList.Count > 0)
                        //{
                        //    odCrl = odCrlList.First();
                        //}
                        //string[] odcoms = odCrl.ComponenGroup.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        //int odCount = odcoms.Where(u => u == "012002").Count();

                        //if (odCount == 0)
                        //{
                        Model.Order_Form_T frmOrder = new Model.Order_Form_T();
                        Help.FuZhi<Model.Order_Form_T>.FZ(ref frmOrder, info);
                        Help.Log.Debug("SetOrder_Form ", "    11");
                        string mername = base.DBSession.IView_Order_FormDAL.GetListBy("select * from View_Order_Form where  FormID=" + frmOrder.FormID).First().MerName;
                        Help.Log.Debug("SetOrder_Form ", "    12");

                        List<Model.Order_Oper_T> orders = base.DBSession.IOrder_Oper_TDAL.GetListBy("select * from [Order_Oper_T] ");
                        Help.Log.Debug("SetOrder_Form ", "    13");
                        List<int> operids = new List<int>();
                        Help.Log.Debug("SetOrder_Form", "  FormMerID=" + frmOrder.FormMerID);
                        foreach (var order in orders)
                        {
                            //Help.Log.Debug("SetOrder_Form", " order.MerID=" + order.MerID);
                            if (!string.IsNullOrWhiteSpace(order.MerID))
                            {
                                string[] orderMer = order.MerID.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (var ormr in orderMer)
                                {
                                    // Help.Log.Debug("SetOrder_Form", " ormr=" + ormr);
                                    if (ormr == frmOrder.FormMerID)
                                    {
                                        operids.Add(order.OperID);
                                        Help.Log.Debug("SetOrder_Form", " operid=" + OperID);
                                        break;
                                    }
                                }

                            }

                        }
                        string operStr = "";
                        operStr = String.Join(",", operids);
                        Help.Log.Debug("SetOrder_Form  ", "   14   ");
                        frmOrder.FormDishesID = operStr;
                        frmOrder.FormMerID = mername;
                        frmOrder.Type = "200004";

                        //frmOrder.IsEva = OperID;      //用IsEva保存OperID
                        Help.Log.Debug("SetOrder_Form  ", "   15");
                        Help.ALL_DataV.PushQueue.Enqueue(frmOrder);
                    }
                    //  }
                    //   }
                    // }
                    //  }
                    #endregion
                    Help.Log.Debug("SetOrder_Form    ", " 16");
                    Model.Order_Form_T ordert = base.GetListBy(u => u.FormID == fm).First();
                    Help.Log.Debug("SetOrder_Form   ", "  17");
                    Help.Log.Debug("SetOrder_Form", "已更改    SetOrder_Form     FormID=" + ordert.FormID + "   FormBY=" + ordert.FormBY + "    IsPay=" + ordert.IsPay);
                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新失败";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("更新商户的订单状态和备注信息失败：" + ex.Message);
                result.BS = "-1";
                result.Msg = "更新失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }
        #endregion

        #region 计算优惠
        /// <summary>
        /// 
        /// </summary>
        /// <param name="DishIDs">菜品ID集合“,”分隔</param>
        /// <param name="DistCount">数量集合“,”分隔</param>
        /// <param name="MerID">商户ID</param>
        /// <param name="PayID">钱包ID</param>
        /// <param name="PricType">钱包类型（0：钱包，1：第三方）</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string CountDiscount(string[] DishIDs, int[] DistCount, string MerID, string PayID, int PricType, int IsTake, string YZM, int RETID)
        {
            Model.OrderTotal OT = new OrderTotal();
            try
            {
                #region 计算优惠
                double i_优惠后总价 = 0, i_总价 = 0;
                List<string> DishIDsList = new List<string>();
                List<int> DistCountList = new List<int>();
                for (int i = 0; i < DistCount.Length; i++)
                {
                    if (DistCount[i] != 0)
                    {
                        DishIDsList.Add(DishIDs[i]);
                        DistCountList.Add(DistCount[i]);
                    }
                }
                int[] dic = new int[DistCountList.Count];
                for (int i = 0; i < DistCountList.Count; i++)
                {
                    dic[i] = DistCountList[i];
                }
                List<Model.Order_Dishes_T> Dist = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => DishIDsList.Contains(u.DishesID));
                OT.DishList = Dist;
                OT.CountArr = dic;
                Model.Order_Mer_T Mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == MerID).First();
                double i_商品总价 = 0, i_打包费总价 = 0, i_消费积分 = 0, i_订餐份数 = 0;
                for (int i = 0; i < Dist.Count; i++)
                {
                    if (Dist[i].DishesIsInt == 0)
                    {
                        i_订餐份数 += dic[i];
                        i_商品总价 += Dist[i].DishesPay * dic[i];
                        i_打包费总价 += Dist[i].DelPackMon * dic[i];
                    }
                    else
                    {
                        i_订餐份数 += dic[i];
                        i_消费积分 += Dist[i].DishesPay * dic[i];
                        i_打包费总价 += Dist[i].DelPackMon * dic[i];
                    }
                }
                i_总价 = i_商品总价 + i_打包费总价;
                int i_派送费更多 = 0;
                if (Mer.Greater > 0 & i_订餐份数 > Mer.Greater)
                {
                    int djfs = (int)i_订餐份数 - Mer.Greater;
                    double fs = djfs / Mer.HowCount;
                    if (fs == 0) fs = 1;
                    i_派送费更多 = (int)fs * Mer.AddMoney;
                }
                i_总价 += Mer.DelFormMon + i_派送费更多;
                i_优惠后总价 = i_总价;
                OT.TotalPoint = i_消费积分.ToString();
                OT.DelFormMon = Mer.DelFormMon + i_派送费更多;

                OT.DelMonTxt = Mer.DelMonTxt;
                if (PayID != "")
                {
                    #region 计算优惠
                    Model.Order_MerPricing_T MerPrin = new Model.Order_MerPricing_T();
                    try
                    {
                        MerPrin = base.DBSession.IOrder_MerPricing_TDAL.GetListBy(u => u.PricID == PayID & u.PricType == PricType & u.PricState == 1).First();
                    }
                    catch (Exception)
                    {
                        goto addVal;
                    }
                    if (MerPrin.MerID != MerID)
                    {
                        result.BS = "-10";
                        result.Msg = "不能使用此优惠";
                        return os.StringOfObject(result, RETID);
                    }
                    if (MerPrin.IsFirstMon != 0)
                    {
                        if (MerPrin.IsFirstMon > i_商品总价)
                        {
                            result.BS = "-11";
                            result.Msg = "用户不能使用此优惠";
                            return os.StringOfObject(result, RETID);
                        }
                        i_优惠后总价 -= MerPrin.IsFirstMon;
                    }
                    if (MerPrin.MonType == 0)
                    {
                        i_优惠后总价 -= MerPrin.PricMon;
                    }
                    else
                    {
                        double d_总价 = 0, d_菜品总价 = 0, d_包装总价 = i_打包费总价, d_配送费 = Mer.DelFormMon;
                        if (MerPrin.IsPackMon == 1)
                        {
                            d_包装总价 = i_打包费总价 * MerPrin.PricMon / 100;

                        }
                        d_菜品总价 = i_商品总价 * MerPrin.PricMon / 100;
                        if (MerPrin.IsFormMon == 1)
                        {
                            d_配送费 = (Mer.DelFormMon + i_派送费更多) * MerPrin.PricMon / 100;
                            OT.DelFormMon = d_配送费;

                        }
                        d_总价 = d_菜品总价 + d_包装总价 + d_配送费;
                        switch (MerPrin.PricRem)
                        {
                            case 0:
                                d_总价 = Math.Round(d_总价);
                                break;
                            case 1:
                                d_总价 = (int)d_总价;
                                break;
                        }
                        i_优惠后总价 = d_总价;
                    }
                    #endregion
                }

                #endregion
                addVal:
                OT.Total = i_优惠后总价.ToString();
                OT.Discount = ((i_总价 - i_优惠后总价)).ToString();
            }
            catch (Exception)
            {
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            if (IsTake == 2)
            {
                OT.Total = (int.Parse(OT.Total) - OT.DelFormMon).ToString();
                OT.Discount = (double.Parse(OT.Discount) - OT.DelFormMon).ToString();

            }
            result.BS = "1";
            result.Msg = "读取成功";
            result.rows = OT;
            return os.StringOfObject(result, RETID);
        }
        #endregion

        #region GetOrderTime
        /// <summary>
        /// 获取送餐时间
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetOrderTime(string MerID, string YZM, int RETID)
        {

            OrderTime OT = new OrderTime();
            try
            {
                #region MyRegion
                string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                int day = int.Parse(time.Substring(0, 8));
                string tm = time.Substring(8, 4);
                List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy("SELECT * FROM Order_Shelves_T where SheDateB<=" + day + " and SheDateE>=" + day + " and MerID='" + MerID + "' and  SheTimeB<'" + tm + "' and SheTimeE > '" + tm + "' and SheState=1");
                if (ShelList.Count > 0)
                {
                    List<string> rq = new List<string>();
                    List<string> sj = new List<string>();
                    for (int i = 0; i < ShelList[0].MaDay + 1; i++)
                    {
                        rq.Add(DateTime.Now.AddDays(i).ToString("yyyy-MM-dd"));
                    }
                    OT.DeliveryDate = rq;
                    if (ShelList[0].MaTime != "0|0")
                    {
                        #region MyRegion
                        string[] times = ShelList[0].MaTime.Split('|');
                        int ks = int.Parse(times[0].Substring(0, 2));
                        int js = int.Parse(times[1].Substring(0, 2));
                        DateTime ks1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, ks, int.Parse(times[0].Substring(2, 2)), 0);
                        DateTime js1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, js, int.Parse(times[1].Substring(2, 2)), 0);
                        if (DateTime.Now < js1)
                        {
                            DateTime ksdt = DateTime.Now.AddMinutes(base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == MerID).First().DelTime);
                            if (ks1 < ksdt)
                            {
                                sj.Add(ksdt.ToString("HH:mm"));
                                int s = ksdt.Minute;
                                if (s > 0 & s < 15)
                                {
                                    ksdt = ksdt.AddMinutes(15 - s);
                                }
                                if (s > 15 & s < 30)
                                {
                                    ksdt = ksdt.AddMinutes(30 - s);
                                }
                                if (s > 30 & s < 45)
                                {
                                    ksdt = ksdt.AddMinutes(45 - s);
                                }
                                if (s > 45 & s < 59)
                                {
                                    ksdt = ksdt.AddMinutes(60 - s);
                                }

                            }
                            else
                            {
                                ksdt = ks1;
                            }
                            sj.Add(ksdt.ToString("HH:mm"));
                            DateTime jsdt = new DateTime(ksdt.Year, ksdt.Month, ksdt.Day, js, int.Parse(times[1].Substring(2, 2)), 0);

                            while (jsdt > ksdt)
                            {
                                string tim = ksdt.AddMinutes(15).ToString("HH:mm");
                                sj.Add(tim);
                                ksdt = ksdt.AddMinutes(15);
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        DateTime ksdt = DateTime.Now.AddMinutes(base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == MerID).First().DelTime);
                        sj.Add(ksdt.ToString("HH:mm"));
                    }
                    OT.DeliveryTime = sj;
                }
                #endregion
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "读取失败";
                return os.StringOfObject(result, RETID);
            }
            result.BS = "1";
            result.Msg = "读取成功";
            result.rows = OT;
            return os.StringOfObject(result, RETID);
        }
        #endregion

        /// <summary>
        /// 从新下单
        /// </summary>
        /// <param name="FormID">订单ID</param>
        /// <param name="PayID">钱包ID</param>
        /// <param name="lx">1算先价格 2修改订单 3删除</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string ReBookOrder(int FormID, string PayID, int lx, int IsTake, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            try
            {
                Model.Order_Form_T info = new Model.Order_Form_T();
                info = base.GetListBy(u => u.FormID == FormID & u.FormState == 1).First();
                info.IsTake = IsTake;
                bool br = Regex.IsMatch(PayID, "^[0-9]*$");
                if (br)
                {
                    info.FormPayType = 1;
                }
                else
                {
                    info.FormPayType = 2;
                }
                string[] dishs = info.FormDishesID.Split(',');

                string[] DCount = info.FormDishesNun.Split(',');
                switch (lx)
                {
                    case 1:

                        int[] dd = new int[DCount.Length];
                        for (int i = 0; i < DCount.Length; i++)
                        {
                            dd[i] = int.Parse(DCount[i]);
                        }

                        Order_MerPricing_T mp = new Order_MerPricing_T();
                        return mp.CalcDiscount(dishs, dd, info.FormMerID, PayID, IsTake, YZM, RETID);
                    case 3:
                        Model.Order_Form_T delof = base.GetListBy(u => u.FormID == info.FormID).First();
                        delof.FormState = 0;
                        base.Modify(delof);
                        try
                        {
                            string time11 = info.FormTime;
                            int day11 = int.Parse(time11.Substring(0, 8));
                            int ti11 = int.Parse(time11.Substring(8, 4));
                            List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(u => u.SheDateB <= day11 & u.SheDateE >= day11 & u.MerID == info.FormMerID & u.SheState == 1);
                            Model.Order_Shelves_T SheLve = new Model.Order_Shelves_T();
                            foreach (var item in ShelList)
                            {
                                if (int.Parse(item.SheTimeB) < ti11 & ti11 < int.Parse(item.SheTimeE))
                                {
                                    SheLve = item;
                                    break;
                                }
                            }
                            List<Model.Order_Sales_T> SaleList = base.DBSession.IOrder_Sales_TDAL.GetListBy(u => u.SalesDate == day11 & u.SheID == SheLve.SheID & u.SheState == 1);
                            for (int i = 0; i < dishs.Length; i++)
                            {
                                Model.Order_Sales_T tm = (from m in SaleList where m.DishesID == dishs[i] select m).ToList().First();
                                tm.HaveNub += int.Parse(DCount[i]);
                                base.DBSession.IOrder_Sales_TDAL.Modify(tm);
                            }

                            if (info.FormPayType != 2)
                            {
                                Model.Order_FlowMon_T OFM = base.DBSession.IOrder_FlowMon_TDAL.GetListBy(u => u.OrdrID == info.FormID).First();
                                base.DBSession.IOrder_FlowMon_TDAL.Del(OFM);
                            }
                        }
                        catch (Exception)
                        {

                        }

                        result.BS = "1";
                        result.Msg = "删除订单成功";
                        return os.StringOfObject(result, RETID);
                }
                #region 普通用户订单
                Model.Order_Mer_T Mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                double i_优惠后总价 = 0, i_总价 = 0;
                string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                int day = int.Parse(time.Substring(0, 8));
                int ti = int.Parse(time.Substring(8, 4));
                string[] DishIDs = info.FormDishesID.Split(',');
                string[] DistCount = info.FormDishesNun.Split(',');

                #region 检测钱包是否能用
                switch (info.FormPayType)
                {
                    case 1:
                        #region 钱包
                        Model.Order_UserWalt_T UserWalt = new Model.Order_UserWalt_T();
                        try
                        {
                            int z = int.Parse(PayID);
                            UserWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        }
                        catch (Exception)
                        {
                            result.BS = "-99";
                            result.Msg = "钱包数据异常";
                            return os.StringOfObject(result, RETID);
                        }
                        string str_depID = base.DBSession.IView_UserDAL.GetListBy(u => u.AccID == info.AccID).First().DepID;
                        if (str_depID.Trim() == "")
                        {
                            result.BS = "-6";
                            result.Msg = "用户没有使用此钱包的权限";
                            return os.StringOfObject(result, RETID);
                        }
                        Model.Order_Walt_T orderWalt = new Model.Order_Walt_T();
                        string WID = UserWalt.WaltID.ToString();
                        orderWalt = base.DBSession.IOrder_Walt_TDAL.GetListBy(u => u.WaltID == WID).First();
                        string[] DepList = orderWalt.WaltDep.Split(',');
                        bool jg = true;
                        foreach (var item in DepList)
                        {
                            if (item == str_depID.Substring(0, item.Length))
                            {
                                jg = false;
                                break;
                            }
                        }
                        if (jg)
                        {
                            result.BS = "-7";
                            result.Msg = "用户没有使用此钱包的权限";
                            return os.StringOfObject(result, RETID);
                        }
                        if (!orderWalt.WaltMer.Contains(info.FormMerID))
                        {
                            result.BS = "-8";
                            result.Msg = "该商户不能使用此钱包";
                            return os.StringOfObject(result, RETID);
                        }

                        break;
                    #endregion
                    case 2:
                        #region 第三方
                        Model.Order_Pay_T OrderPay;
                        try
                        {

                            OrderPay = base.DBSession.IOrder_Pay_TDAL.GetListBy(u => u.PayID == PayID).First();
                            if (OrderPay.PayOpen != 2 & OrderPay.PayOpen != 3)
                            {
                                result.BS = "-9";
                                result.Msg = "用户没有使用此钱包的权限";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                        catch (Exception)
                        {
                            result.BS = "-99";
                            result.Msg = "钱包数据异常";
                            return os.StringOfObject(result, RETID);
                        }
                        #endregion
                        break;
                    default:
                        break;
                }
                #endregion
                #region 计算优惠

                List<Model.Order_Dishes_T> Dist = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => DishIDs.Contains(u.DishesID));
                double i_商品总价 = 0, i_打包费总价 = 0, i_消费平台积分 = 0, i_消费商户积分 = 0, i_订餐份数 = 0;
                string FormDisheName = "", FormDishesMon = "", FornDishesInt = "";
                int jf_平台 = 0, jf_商户 = 0;
                Model.Order_Key_T Key = base.DBSession.IOrder_Key_TDAL.GetListBy(u => u.ComOpen == u.ComOpen).First();
                List<Model.Order_Int_T> OI_平台list = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == "0");
                List<Model.Order_Int_T> OI_商户list = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID);

                for (int i = 0; i < Dist.Count; i++)
                {

                    FormDisheName += "," + Dist[i].DishesNmae;
                    if (Dist[i].DishesIsInt == 0)
                    {

                        FormDishesMon += "," + Dist[i].DishesPay;
                        FornDishesInt += ",0";
                    }
                    else
                    {
                        FormDishesMon += ",0";
                        FornDishesInt += "," + Dist[i].DishesPay;
                    }

                    if (Dist[i].DishesIsInt == 0)
                    {
                        i_订餐份数 += int.Parse(DistCount[i]);
                        i_商品总价 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                        i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                        #region 积分
                        switch (Dist[i].DishesEnableInt)
                        {
                            case 1:
                                if (OI_平台list.Count > 0)
                                {
                                    switch (OI_平台list[0].IntUn)
                                    {
                                        case 1:
                                            jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe;
                                            break;
                                        case 2:
                                            jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe / 10;
                                            break;
                                        default:
                                            jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe / 100;
                                            break;
                                    }
                                }
                                break;
                            case 2:
                                if (OI_商户list.Count > 0)
                                {
                                    switch (OI_商户list[0].IntUn)
                                    {
                                        case 1:
                                            jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe;
                                            break;
                                        case 2:
                                            jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe / 10;
                                            break;
                                        default:
                                            jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe / 100;
                                            break;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                        #endregion
                    }
                    else
                    {
                        i_订餐份数 += int.Parse(DistCount[i]);
                        if (Dist[i].DishesIsInt == 1)
                        {
                            i_消费平台积分 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                            i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                        }
                        else
                        {
                            i_消费商户积分 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                            i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                        }
                    }
                }
                info.FormDisheName = FormDisheName.Remove(0, 1);
                info.FormDishesMon = FormDishesMon.Remove(0, 1);
                info.FornDishesInt = FornDishesInt.Remove(0, 1);
                i_总价 = i_商品总价 + i_打包费总价;
                int i_派送费更多 = 0;
                if (Mer.Greater > 0 & i_订餐份数 > Mer.Greater)
                {
                    int djfs = (int)i_订餐份数 - Mer.Greater;
                    double fs = djfs / Mer.HowCount;
                    if (fs == 0) fs = 1;
                    i_派送费更多 = (int)fs * Mer.AddMoney;
                }
                i_总价 += Mer.DelFormMon + i_派送费更多;//配送费 
                i_优惠后总价 = i_总价;
                #endregion

                #region 计算钱包
                List<Model.Order_MerPricing_T> MerList = new List<Model.Order_MerPricing_T>();
                MerList = base.DBSession.IOrder_MerPricing_TDAL.GetListBy(u => u.MerID == info.FormMerID & u.PayID == PayID & u.MonType == info.FormPayType & u.PricState == 1);
                if (MerList.Count > 0)
                {
                    Model.Order_MerPricing_T MerPrin = MerList[0];
                    #region 计算优惠
                    if (MerPrin.MerID != info.FormMerID)
                    {
                        result.BS = "-10";
                        result.Msg = "不能使用此优惠";
                        return os.StringOfObject(result, RETID);
                    }
                    info.DelFormMon = (int)Mer.DelFormMon;
                    info.DelPackMon = (int)i_打包费总价;
                    if (MerPrin.MonType == 0)
                    {
                        i_优惠后总价 -= MerPrin.PricMon;
                    }
                    else
                    {
                        double d_总价 = 0, d_菜品总价 = 0, d_包装总价 = i_打包费总价, d_配送费 = Mer.DelFormMon + i_派送费更多;
                        if (MerPrin.IsPackMon == 1)
                        {
                            d_包装总价 = i_打包费总价 * MerPrin.PricMon / 100;
                            info.DelPackMon = (int)d_包装总价;
                        }
                        if (MerPrin.IsFirstMon != 0)
                        {
                            if (MerPrin.IsFirstMon > i_商品总价)
                            {
                                d_菜品总价 = i_商品总价;
                            }
                            else
                            {
                                d_菜品总价 = (i_商品总价 - MerPrin.IsFirstMon) * MerPrin.PricMon / 100 + MerPrin.IsFirstMon;
                            }
                        }
                        else
                        {
                            d_菜品总价 = i_商品总价 * MerPrin.PricMon / 100;
                        }
                        if (MerPrin.IsFormMon == 1)
                        {
                            d_配送费 = (i_派送费更多 + Mer.DelFormMon) * MerPrin.PricMon / 100;
                            info.DelFormMon = (int)d_配送费;
                        }
                        d_总价 = d_菜品总价 + d_包装总价 + d_配送费;
                        switch (MerPrin.PricRem)
                        {
                            case 0:
                                d_总价 = Math.Round(d_总价);
                                break;
                            case 1:
                                d_总价 = (int)d_总价;
                                break;
                        }
                        i_优惠后总价 = d_总价;
                    }
                    #endregion
                    //addVal:
                    //    info.FormAllMon = (int)i_总价;
                    //    info.FormPayMon = (int)i_优惠后总价;
                }
                else
                {
                    info.DelFormMon = (int)Mer.DelFormMon + i_派送费更多;
                    info.DelPackMon = (int)i_打包费总价;
                }
                if (info.FormPayMon == 0)
                {
                    if (info.FormPayType == 1)
                    {
                        Model.Order_UserWalt_T Uw = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        if (Uw.WaltNowNub < (int)i_优惠后总价)
                        {
                            result.BS = "-12";
                            result.Msg = "钱包余额不足";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                }
                #endregion

                #region 计算积分

                if (Key.IntOpenPT == 0 & i_消费平台积分 > 0)
                {
                    result.BS = "-13";
                    result.Msg = "不允许使用平台积分";
                    return os.StringOfObject(result, RETID);
                }
                if (Key.IntOpenSH == 0 & i_消费商户积分 > 0)
                {
                    result.BS = "-14";
                    result.Msg = "不允许使用商户积分";
                    return os.StringOfObject(result, RETID);
                }
                Model.Order_Int_T Oi_平台 = new Model.Order_Int_T(), Oi_商户 = new Model.Order_Int_T();
                if (i_消费平台积分 > 0)
                {
                    try
                    {
                        Oi_平台 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == "0").First();
                        string intid = Oi_平台.IntID;
                        int nownum = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.IntID == intid & u.AccID == info.AccID).First().IntNowNub;
                        if (nownum < i_消费平台积分)
                        {
                            result.BS = "-15";
                            result.Msg = "平台积分不足";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    catch (Exception)
                    {
                        result.BS = "-16";
                        result.Msg = "查询平台积分异常";
                        return os.StringOfObject(result, RETID);
                    }
                }
                if (i_消费商户积分 > 0)
                {
                    try
                    {
                        Oi_商户 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                        string intid = Oi_商户.IntID;
                        int nownum = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.IntID == intid & u.AccID == info.AccID).First().IntNowNub;
                        if (nownum < i_消费商户积分)
                        {
                            result.BS = "-17";
                            result.Msg = "商户积分不足";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    catch (Exception)
                    {
                        result.BS = "-18";
                        result.Msg = "查询商户积分异常";
                        return os.StringOfObject(result, RETID);
                    }
                }
                #endregion
                info.FormAllMon = (int)i_总价;
                info.FormPreMon = (int)(i_总价 - i_优惠后总价);

                info.IsEva = 0;
                info.LastOper = 0;
                info.LastTime = time;
                info.FormState = 1;
                info.FormTime = time;
                info.FormBY = "1A02";
                info.LastOper = 1;
                info.FormPayMon = (int)i_优惠后总价;
                if (info.IsTake == 2)
                {
                    info.FormPayMon = info.FormPayMon - info.DelFormMon;
                    info.DelFormMon = 0;
                }
                switch (info.FormPayType)
                {

                    case 2:
                        info.IsPay = 0;
                        info.DelFormMon = (int)Mer.DelFormMon;
                        info.DelPackMon = (int)i_打包费总价;
                        result.rows = info.FormID + "|" + info.FormPayMon;
                        break;
                    default:
                        info.IsPay = 0;
                        info.DelFormMon = (int)Mer.DelFormMon;
                        info.DelPackMon = (int)i_打包费总价;
                        result.rows = info.FormID + "|" + info.FormPayMon;
                        result.total = 1;
                        break;
                }
                if (info.IsTake == 2)
                {
                    info.DelFormMon = 0;
                }

                base.Modify(info);
                base.DBSession.IOrder_FlowMon_TDAL.DelBy(u => u.OrdrID == info.FormID);
                if (info.FormPayType != 2)
                {
                    try
                    {

                        Model.Order_UserWalt_T USerWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        Model.Order_FlowMon_T OFM = new Model.Order_FlowMon_T();
                        OFM.FlowMonID = Help.GetSysKey.GetKey("FlowMonKey");
                        OFM.AccID = info.AccID;
                        OFM.WaltFlowType = "1A0009";
                        OFM.WaltID = PayID;
                        OFM.WaltNowNub = USerWalt.WaltNowNub;
                        OFM.WaltHaveNub = USerWalt.WaltNowNub;
                        OFM.WaltEndNub = USerWalt.WaltNowNub; ;
                        OFM.WaltFlowTime = time;
                        OFM.WaltFlowOper = 1;
                        OFM.OrdrID = info.FormID;
                        base.DBSession.IOrder_FlowMon_TDAL.Add(OFM);
                    }
                    catch (Exception)
                    {

                    }

                }
                result.BS = "1";
                result.Msg = "下单成功";

                //Help.ALL_DataV.PushQueue.Enqueue(info);
                #endregion
            }
            catch (DbEntityValidationException dbex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = dbex.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection<DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                //Console.WriteLine(errors.ToString());
                WriteLog.WriteW("AddOrder_OperationFlow异常：" + errors.ToString());

            }
            catch (DbUpdateException ex)
            {
                WriteLog.WriteW("下订单信息失败DbUpdateException：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("普通用户重新下订单信息失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            return os.StringOfObject(result, RETID);
        }

        public string ReBookOrder2(int FormID, string PayID, int lx, int IsTake, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            try
            {
                Model.Order_Form_T info = new Model.Order_Form_T();
                info = base.GetListBy(u => u.FormID == FormID & u.FormState == 1).First();
                info.IsTake = IsTake;
                bool br = Regex.IsMatch(PayID, "^[0-9]*$");
                if (br)
                {
                    info.FormPayType = 1;
                }
                else
                {
                    info.FormPayType = 2;
                }
                string[] dishs = info.FormDishesID.Split(',');
                string[] DCount = info.FormDishesNun.Split(',');
                switch (lx)
                {
                    case 1:
                        if (IsTake == 2)
                        {
                            info.FormPayMon = info.FormPayMon - info.DelFormMon;
                            info.DelFormMon = 0;
                        }
                        OrderTotal OT = new OrderTotal();
                        OT.Total = info.FormPayMon.ToString();
                        result.rows = OT;
                        result.BS = "1";
                        result.Msg = "查询订单实际支付价格成功";
                        return os.StringOfObject(result, RETID);
                    case 3:
                        Model.Order_Form_T delof = base.GetListBy(u => u.FormID == info.FormID).First();
                        delof.FormState = 0;
                        int ret = base.Modify(delof);
                        if (ret > 0)
                        {
                            result.BS = "1";
                            result.Msg = "删除订单成功";
                            return os.StringOfObject(result, RETID);
                        }
                        break;
                }                

                #region 检测钱包是否能用
                switch (info.FormPayType)
                {
                    case 1:
                        #region 钱包
                        Model.Order_UserWalt_T UserWalt = new Model.Order_UserWalt_T();
                        try
                        {
                            int z = int.Parse(PayID);
                            UserWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        }
                        catch (Exception)
                        {
                            result.BS = "-99";
                            result.Msg = "钱包数据异常";
                            return os.StringOfObject(result, RETID);
                        }
                        string str_depID = base.DBSession.IView_UserDAL.GetListBy(u => u.AccID == info.AccID).First().DepID;
                        if (str_depID.Trim() == "")
                        {
                            result.BS = "-6";
                            result.Msg = "用户没有使用此钱包的权限";
                            return os.StringOfObject(result, RETID);
                        }
                        Model.Order_Walt_T orderWalt = new Model.Order_Walt_T();
                        string WID = UserWalt.WaltID.ToString();
                        orderWalt = base.DBSession.IOrder_Walt_TDAL.GetListBy(u => u.WaltID == WID).First();
                        string[] DepList = orderWalt.WaltDep.Split(',');
                        bool jg = true;
                        foreach (var item in DepList)
                        {
                            if (item == str_depID.Substring(0, item.Length))
                            {
                                jg = false;
                                break;
                            }
                        }
                        if (jg)
                        {
                            result.BS = "-7";
                            result.Msg = "用户没有使用此钱包的权限";
                            return os.StringOfObject(result, RETID);
                        }
                        if (!orderWalt.WaltMer.Contains(info.FormMerID))
                        {
                            result.BS = "-8";
                            result.Msg = "该商户不能使用此钱包";
                            return os.StringOfObject(result, RETID);
                        }
                        break;
                    #endregion
                    case 2:
                        #region 第三方
                        Model.Order_Pay_T OrderPay;
                        try
                        {
                            OrderPay = base.DBSession.IOrder_Pay_TDAL.GetListBy(u => u.PayID == PayID).First();
                            if (OrderPay.PayOpen != 2 & OrderPay.PayOpen != 3)
                            {
                                result.BS = "-9";
                                result.Msg = "用户没有使用此钱包的权限";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                        catch (Exception)
                        {
                            result.BS = "-99";
                            result.Msg = "钱包数据异常";
                            return os.StringOfObject(result, RETID);
                        }
                        #endregion
                        break;
                    default:
                        break;
                }
                #endregion

                #region 普通用户更新订单
                string time = DateTime.Now.ToString("yyyyMMddHHmmss");

                info.IsEva = 0;
                info.LastOper = 0;
                info.LastTime = time;
                info.FormState = 1;
                info.FormTime = time;
                info.FormBY = "1A02";
                info.LastOper = 1;
                if (info.IsTake == 2)
                {
                    info.FormPayMon = info.FormPayMon - info.DelFormMon;
                    info.DelFormMon = 0;
                }
                switch (info.FormPayType)
                {
                    case 2:
                        info.IsPay = 0;
                        result.rows = info.FormID + "|" + info.FormPayMon;
                        break;
                    default:
                        info.IsPay = 0;
                        result.rows = info.FormID + "|" + info.FormPayMon;
                        result.total = 1;
                        break;
                }                

                base.Modify(info);
                base.DBSession.IOrder_FlowMon_TDAL.DelBy(u => u.OrdrID == info.FormID);
                if (info.FormPayType != 2)
                {
                    try
                    {
                        Model.Order_UserWalt_T USerWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        Model.Order_FlowMon_T OFM = new Model.Order_FlowMon_T();
                        OFM.FlowMonID = Help.GetSysKey.GetKey("FlowMonKey");
                        OFM.AccID = info.AccID;
                        OFM.WaltFlowType = "1A0009";
                        OFM.WaltID = PayID;
                        OFM.WaltNowNub = USerWalt.WaltNowNub;
                        OFM.WaltHaveNub = USerWalt.WaltNowNub;
                        OFM.WaltEndNub = USerWalt.WaltNowNub; ;
                        OFM.WaltFlowTime = time;
                        OFM.WaltFlowOper = 1;
                        OFM.OrdrID = info.FormID;
                        base.DBSession.IOrder_FlowMon_TDAL.Add(OFM);
                    }
                    catch (Exception)
                    {

                    }

                }
                result.BS = "1";
                result.Msg = "下单成功";

                //Help.ALL_DataV.PushQueue.Enqueue(info);
                #endregion
            }
            catch (DbEntityValidationException dbex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = dbex.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection<DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                //Console.WriteLine(errors.ToString());
                WriteLog.WriteW("AddOrder_OperationFlow异常：" + errors.ToString());

            }
            catch (DbUpdateException ex)
            {
                WriteLog.WriteW("下订单信息失败DbUpdateException：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("普通用户重新下订单信息失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            return os.StringOfObject(result, RETID);
        }

        /// <summary>
        /// 订单提交
        /// </summary>
        /// <param name="Data">Json数据</param>
        /// <param name="PayID">钱包ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string BookOrder(string Data, string PayID, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            #region 执行操作
            try
            {
                WriteLog.WriteW("下订单" + Data);
                Model.Order_Form_T info = ParseClass<Model.Order_Form_T>.StrDeserialize(Data, RETID);

                if (info.Type == "200001")
                {
                    #region 普通用户订单
                    Model.Order_Mer_T Mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                    double i_优惠后总价 = 0, i_总价 = 0;
                    string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                    int day = int.Parse(time.Substring(0, 8));
                    int ti = int.Parse(time.Substring(8, 4));
                    string[] DishIDs = info.FormDishesID.Split(',');
                    string[] DistCount = info.FormDishesNun.Split(',');
                    for (int i = 0; i < DistCount.Length; i++)
                    {
                        if (DistCount[i] == "0")
                        {
                            result.BS = "-21";
                            result.Msg = "菜品数量不能为0";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(u => u.SheDateB <= day & u.SheDateE >= day & u.MerID == info.FormMerID & u.SheState == 1);

                    #region 上架列表
                    Model.Order_Shelves_T SheLve = new Model.Order_Shelves_T();
                    foreach (var item in ShelList)
                    {
                        if (int.Parse(item.SheTimeB) < ti & ti < int.Parse(item.SheTimeE))
                        {
                            SheLve = item;
                            break;
                        }
                    }
                    #endregion

                    #region 菜品
                    List<Model.Order_Sales_T> SaleList = base.DBSession.IOrder_Sales_TDAL.GetListBy(u => u.SalesDate == day & u.SheID == SheLve.SheID & u.SheState == 1);

                    if (SaleList.Count == 0)
                    {
                        string[] ShelveDishIDS = SheLve.DishesID.Split(',');
                        string[] ShelveNumS = SheLve.DishesNub.Split(',');
                        SaleList = new List<Model.Order_Sales_T>();
                        for (int i = 0; i < ShelveDishIDS.Length; i++)
                        {
                            Model.Order_Sales_T Sale = new Model.Order_Sales_T();
                            Sale.SheID = SheLve.SheID;
                            Sale.DishesID = ShelveDishIDS[i];
                            Sale.SalesNub = int.Parse(ShelveNumS[i]);
                            Sale.HaveNub = Sale.SalesNub;
                            Sale.IntTime = time;
                            Sale.SalesDate = day;
                            Sale.SheState = 1;
                            Sale.BZ = "";
                            SaleList.Add(Sale);
                        }
                        base.DBSession.IOrder_Sales_TDAL.Add(SaleList);
                    }
                    for (int i = 0; i < DishIDs.Length; i++)
                    {
                        List<Model.Order_Sales_T> tmpList = (from m in SaleList where m.DishesID == DishIDs[i] select m).ToList();
                        if (tmpList.Count == 0)
                        {
                            result.BS = "-1";
                            result.Msg = "菜品没启用";
                            return os.StringOfObject(result, RETID);
                        }
                        else
                        {
                            if (tmpList[0].HaveNub < int.Parse(DistCount[i]))
                            {
                                result.BS = "-2";
                                result.Msg = "菜品不够";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                    }
                    #endregion

                    #region 检测钱包是否能用
                    switch (info.FormPayType)
                    {
                        case 1:
                            #region 钱包
                            Model.Order_UserWalt_T UserWalt = new Model.Order_UserWalt_T();
                            try
                            {
                                int z = int.Parse(PayID);
                                UserWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                            }
                            catch (Exception)
                            {
                                result.BS = "-99";
                                result.Msg = "钱包数据异常";
                                return os.StringOfObject(result, RETID);
                            }
                            string str_depID = base.DBSession.IView_UserDAL.GetListBy(u => u.AccID == info.AccID).First().DepID;
                            if (str_depID.Trim() == "")
                            {
                                result.BS = "-6";
                                result.Msg = "用户没有使用此钱包的权限";
                                return os.StringOfObject(result, RETID);
                            }
                            Model.Order_Walt_T orderWalt = new Model.Order_Walt_T();
                            string WID = UserWalt.WaltID.ToString();
                            orderWalt = base.DBSession.IOrder_Walt_TDAL.GetListBy(u => u.WaltID == WID).First();
                            string[] DepList = orderWalt.WaltDep.Split(',');
                            bool jg = true;
                            foreach (var item in DepList)
                            {
                                if (item == str_depID.Substring(0, item.Length))
                                {
                                    jg = false;
                                    break;
                                }
                            }
                            if (jg)
                            {
                                result.BS = "-7";
                                result.Msg = "用户没有使用此钱包的权限";
                                return os.StringOfObject(result, RETID);
                            }
                            if (!orderWalt.WaltMer.Contains(info.FormMerID))
                            {
                                result.BS = "-8";
                                result.Msg = "该商户不能使用此钱包";
                                return os.StringOfObject(result, RETID);
                            }

                            break;
                        #endregion
                        case 2:
                            #region 第三方
                            Model.Order_Pay_T OrderPay;
                            try
                            {

                                OrderPay = base.DBSession.IOrder_Pay_TDAL.GetListBy(u => u.PayID == PayID).First();
                                if (OrderPay.PayOpen != 2 & OrderPay.PayOpen != 3)
                                {
                                    result.BS = "-9";
                                    result.Msg = "用户没有使用此钱包的权限";
                                    return os.StringOfObject(result, RETID);
                                }
                            }
                            catch (Exception)
                            {
                                result.BS = "-99";
                                result.Msg = "钱包数据异常";
                                return os.StringOfObject(result, RETID);
                            }
                            #endregion
                            break;
                        default:
                            break;
                    }
                    #endregion

                    #region 计算优惠
                    List<Model.Order_Dishes_T> Dist = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => DishIDs.Contains(u.DishesID));
                    double i_商品总价 = 0, i_打包费总价 = 0, i_消费平台积分 = 0, i_消费商户积分 = 0, i_订餐份数 = 0;
                    string FormDisheName = "", FormDishesMon = "", FornDishesInt = "";
                    int jf_平台 = 0, jf_商户 = 0;
                    Model.Order_Key_T Key = base.DBSession.IOrder_Key_TDAL.GetListBy(u => u.ComOpen == u.ComOpen).First();
                    List<Model.Order_Int_T> OI_平台list = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == "0");
                    List<Model.Order_Int_T> OI_商户list = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID);

                    for (int i = 0; i < Dist.Count; i++)
                    {

                        FormDisheName += "," + Dist[i].DishesNmae;
                        if (Dist[i].DishesIsInt == 0)
                        {
                            FormDishesMon += "," + Dist[i].DishesPay;
                            FornDishesInt += ",0";
                        }
                        else
                        {
                            FormDishesMon += ",0";
                            FornDishesInt += "," + Dist[i].DishesPay;
                        }

                        if (Dist[i].DishesIsInt == 0)
                        {
                            i_订餐份数 += int.Parse(DistCount[i]);
                            i_商品总价 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                            i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                            #region 积分
                            switch (Dist[i].DishesEnableInt)
                            {
                                case 1:
                                    if (OI_平台list.Count > 0)
                                    {
                                        switch (OI_平台list[0].IntUn)
                                        {
                                            case 1:
                                                jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe;
                                                break;
                                            case 2:
                                                jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe / 10;
                                                break;
                                            default:
                                                jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe / 100;
                                                break;
                                        }
                                    }
                                    break;
                                case 2:
                                    if (OI_商户list.Count > 0)
                                    {
                                        switch (OI_商户list[0].IntUn)
                                        {
                                            case 1:
                                                jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe;
                                                break;
                                            case 2:
                                                jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe / 10;
                                                break;
                                            default:
                                                jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe / 100;
                                                break;
                                        }
                                    }
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                        }
                        else
                        {
                            i_订餐份数 += int.Parse(DistCount[i]);
                            if (Dist[i].DishesIsInt == 1)
                            {
                                i_消费平台积分 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                                i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                            }
                            else
                            {
                                i_消费商户积分 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                                i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                            }
                        }
                    }
                    info.FormDisheName = FormDisheName.Remove(0, 1);
                    info.FormDishesMon = FormDishesMon.Remove(0, 1);
                    info.FornDishesInt = FornDishesInt.Remove(0, 1);
                    i_总价 = i_商品总价 + i_打包费总价;
                    int i_派送费更多 = 0;
                    if (Mer.Greater > 0 & i_订餐份数 > Mer.Greater)
                    {
                        int djfs = (int)i_订餐份数 - Mer.Greater;
                        double fs = djfs / Mer.HowCount;
                        if (fs == 0) fs = 1;
                        i_派送费更多 = (int)fs * Mer.AddMoney;
                    }
                    i_总价 += Mer.DelFormMon + i_派送费更多;//配送费 
                    i_优惠后总价 = i_总价;
                    #endregion

                    #region 计算钱包
                    List<Model.Order_MerPricing_T> MerList = new List<Model.Order_MerPricing_T>();

                    MerList = base.DBSession.IOrder_MerPricing_TDAL.GetListBy(u => u.MerID == info.FormMerID & u.PricState == 1 & u.PayID == PayID);
                    if (MerList.Count > 0)
                    {
                        Model.Order_MerPricing_T MerPrin = MerList[0];
                        #region 计算优惠
                        if (MerPrin.MerID != info.FormMerID)
                        {
                            result.BS = "-10";
                            result.Msg = "不能使用此优惠";
                            return os.StringOfObject(result, RETID);
                        }
                        info.DelFormMon = (int)Mer.DelFormMon + i_派送费更多;
                        info.DelPackMon = (int)i_打包费总价;
                        if (MerPrin.MonType == 0)
                        {
                            i_优惠后总价 -= MerPrin.PricMon;
                        }
                        else
                        {
                            double d_总价 = 0, d_菜品总价 = 0, d_包装总价 = i_打包费总价, d_配送费 = Mer.DelFormMon + i_派送费更多;
                            if (MerPrin.IsPackMon == 1)
                            {
                                d_包装总价 = i_打包费总价 * MerPrin.PricMon / 100;
                                info.DelPackMon = (int)d_包装总价;
                            }
                            if (MerPrin.IsFirstMon != 0)
                            {
                                if (MerPrin.IsFirstMon > i_商品总价)
                                {
                                    d_菜品总价 = i_商品总价;
                                }
                                else
                                {
                                    d_菜品总价 = (i_商品总价 - MerPrin.IsFirstMon) * MerPrin.PricMon / 100 + MerPrin.IsFirstMon;
                                }
                            }
                            else
                            {
                                d_菜品总价 = i_商品总价 * MerPrin.PricMon / 100;
                            }
                            if (MerPrin.IsFormMon == 1)
                            {
                                d_配送费 = (Mer.DelFormMon + i_派送费更多) * MerPrin.PricMon / 100;
                                info.DelFormMon = (int)d_配送费;
                            }
                            d_总价 = d_菜品总价 + d_包装总价 + d_配送费;
                            switch (MerPrin.PricRem)
                            {
                                case 0:
                                    d_总价 = Math.Round(d_总价);
                                    break;
                                case 1:
                                    d_总价 = (int)d_总价;
                                    break;
                            }
                            i_优惠后总价 = d_总价;
                        }
                        #endregion
                        //addVal:
                        //    info.FormAllMon = (int)i_总价;
                        //    info.FormPayMon = (int)i_优惠后总价;
                    }
                    else
                    {
                        info.DelFormMon = (int)Mer.DelFormMon + i_派送费更多;
                        info.DelPackMon = (int)i_打包费总价;
                    }
                    if (info.FormPayMon == 0)
                    {
                        //List<Model.Order_UserWalt_T> llll = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.AccID >0);
                        //  int Wid = int.Parse(PayID);
                        if (info.FormPayType == 1)
                        {
                            Model.Order_UserWalt_T Uw = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                            if (Uw.WaltNowNub < (int)i_优惠后总价)
                            {
                                result.BS = "-12";
                                result.Msg = "钱包余额不足";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                    }
                    #endregion

                    #region 计算积分

                    if (Key.IntOpenPT == 0 & i_消费平台积分 > 0)
                    {
                        result.BS = "-13";
                        result.Msg = "不允许使用平台积分";
                        return os.StringOfObject(result, RETID);
                    }
                    if (Key.IntOpenSH == 0 & i_消费商户积分 > 0)
                    {
                        result.BS = "-14";
                        result.Msg = "不允许使用商户积分";
                        return os.StringOfObject(result, RETID);
                    }
                    Model.Order_Int_T Oi_平台 = new Model.Order_Int_T(), Oi_商户 = new Model.Order_Int_T();
                    if (i_消费平台积分 > 0)
                    {
                        try
                        {
                            Oi_平台 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == "0").First();
                            string intid = Oi_平台.IntID;
                            int nownum = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.IntID == intid & u.AccID == info.AccID).First().IntNowNub;
                            if (nownum < i_消费平台积分)
                            {
                                result.BS = "-15";
                                result.Msg = "平台积分不足";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                        catch (Exception)
                        {
                            result.BS = "-16";
                            result.Msg = "查询平台积分异常";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    if (i_消费商户积分 > 0)
                    {
                        try
                        {
                            Oi_商户 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                            string intid = Oi_商户.IntID;
                            int nownum = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.IntID == intid & u.AccID == info.AccID).First().IntNowNub;
                            if (nownum < i_消费商户积分)
                            {
                                result.BS = "-17";
                                result.Msg = "商户积分不足";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                        catch (Exception)
                        {
                            result.BS = "-18";
                            result.Msg = "查询商户积分异常";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    #endregion

                    info.FormAllMon = (int)i_总价;
                    info.FormPreMon = (int)(i_总价 - i_优惠后总价);
                    info.FormID = int.Parse(Help.GetSysKey.GetKey("FormKey"));

                    info.IsEva = 0;
                    info.LastOper = 0;
                    info.LastTime = time;
                    info.FormState = 1;
                    info.FormTime = time;
                    info.FormBY = "1A02";
                    info.LastOper = 1;
                    info.FormPayMon = (int)i_优惠后总价;
                    if (info.IsTake == 2)
                    {
                        info.FormPayMon = info.FormPayMon - info.DelFormMon;
                        info.DelFormMon = 0;
                    }
                    switch (info.FormPayType)
                    {
                        case 2:
                            info.IsPay = 0;
                            info.DelFormMon = (int)Mer.DelFormMon + i_派送费更多;
                            info.DelPackMon = (int)i_打包费总价;
                            result.rows = info.FormID + "|" + info.FormPayMon;
                            break;
                        default:
                            info.IsPay = 0;
                            info.DelFormMon = (int)Mer.DelFormMon + i_派送费更多;
                            info.DelPackMon = (int)i_打包费总价;
                            result.rows = info.FormID + "|" + info.FormPayMon;
                            result.total = 1;
                            break;
                    }
                    if (info.IsTake == 2)
                    {
                        info.DelFormMon = 0;
                    }
                    base.Add(info);

                    #region 菜品更新
                    SaleList = base.DBSession.IOrder_Sales_TDAL.GetListBy(u => u.SalesDate == day & u.SheID == SheLve.SheID & u.SheState == 1);
                    for (int i = 0; i < DishIDs.Length; i++)
                    {
                        Model.Order_Sales_T tm = (from m in SaleList where m.DishesID == DishIDs[i] select m).ToList().First();
                        tm.HaveNub -= int.Parse(DistCount[i]);
                        base.DBSession.IOrder_Sales_TDAL.Modify(tm);
                    }
                    #endregion

                    if (info.FormPayType != 2)
                    {
                        Model.Order_UserWalt_T USerWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        Model.Order_FlowMon_T OFM = new Model.Order_FlowMon_T();
                        OFM.FlowMonID = Help.GetSysKey.GetKey("FlowMonKey");
                        OFM.AccID = info.AccID;
                        OFM.WaltFlowType = "1A0009";
                        OFM.WaltID = PayID;
                        OFM.WaltNowNub = USerWalt.WaltNowNub;
                        OFM.WaltHaveNub = USerWalt.WaltNowNub;
                        OFM.WaltEndNub = USerWalt.WaltNowNub; ;
                        OFM.WaltFlowTime = time;
                        OFM.WaltFlowOper = 1;
                        OFM.OrdrID = info.FormID;
                        base.DBSession.IOrder_FlowMon_TDAL.Add(OFM);
                    }
                    result.BS = "1";
                    result.Msg = "下单成功";

                    //Help.ALL_DataV.PushQueue.Enqueue(info);
                    return os.StringOfObject(result, RETID);
                    #endregion
                }
                if (info.Type == "200002")
                {
                    #region 企业下订
                    double i_总价 = 0;
                    Model.Order_Mer_T Mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                    string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                    int day = int.Parse(time.Substring(0, 8));
                    int ti = int.Parse(time.Substring(8, 4));
                    string[] DishIDs = info.FormDishesID.Split(',');
                    string[] DistCount = info.FormDishesNun.Split(',');
                    for (int i = 0; i < DistCount.Length; i++)
                    {
                        if (DistCount[i] == "0")
                        {
                            result.BS = "-21";
                            result.Msg = "菜品数量不能为0";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    List<Model.Order_Shelves_T> ShelList = base.DBSession.IOrder_Shelves_TDAL.GetListBy(u => u.SheDateB <= day & u.SheDateE >= day & u.MerID == info.FormMerID & u.SheState == 1);

                    #region 上架列表
                    Model.Order_Shelves_T SheLve = new Model.Order_Shelves_T();
                    foreach (var item in ShelList)
                    {
                        if (int.Parse(item.SheTimeB) < ti & ti < int.Parse(item.SheTimeE))
                        {
                            SheLve = item;
                            break;
                        }
                    }
                    #endregion

                    #region 菜品


                    List<Model.Order_Sales_T> SaleList = base.DBSession.IOrder_Sales_TDAL.GetListBy(u => u.SalesDate == day & u.SheID == SheLve.SheID & u.SheState == 1);

                    if (SaleList.Count == 0)
                    {
                        string[] ShelveDishIDS = SheLve.DishesID.Split(',');
                        string[] ShelveNumS = SheLve.DishesNub.Split(',');
                        SaleList = new List<Model.Order_Sales_T>();
                        for (int i = 0; i < ShelveDishIDS.Length; i++)
                        {
                            Model.Order_Sales_T Sale = new Model.Order_Sales_T();
                            Sale.SheID = SheLve.SheID;
                            Sale.DishesID = ShelveDishIDS[i];
                            Sale.SalesNub = int.Parse(ShelveNumS[i]);
                            Sale.HaveNub = Sale.SalesNub;
                            Sale.IntTime = time;
                            Sale.SalesDate = day;
                            Sale.SheState = 1;
                            Sale.BZ = "";
                            SaleList.Add(Sale);
                        }
                        int asdfi = base.DBSession.IOrder_Sales_TDAL.Add(SaleList);
                    }
                    for (int i = 0; i < DishIDs.Length; i++)
                    {
                        List<Model.Order_Sales_T> tmpList = (from m in SaleList where m.DishesID == DishIDs[i] select m).ToList();
                        if (tmpList.Count == 0)
                        {
                            result.BS = "-1";
                            result.Msg = "菜品没启用";
                            return os.StringOfObject(result, RETID);
                        }
                        else
                        {
                            if (tmpList[0].HaveNub < int.Parse(DistCount[i]))
                            {
                                result.BS = "-2";
                                result.Msg = "菜品不够";
                                return os.StringOfObject(result, RETID);
                            }
                        }
                    }
                    #endregion

                    #region 计算优惠
                    List<Model.Order_Dishes_T> Dist = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => DishIDs.Contains(u.DishesID));
                    double i_商品总价实际价格 = 0, i_打包费总价 = 0, i_订餐份数 = 0; ;
                    string FormDisheName = "", FormDishesMon = "";
                    Model.Order_Key_T Key = base.DBSession.IOrder_Key_TDAL.GetListBy(u => u.ComOpen == u.ComOpen).First();

                    for (int i = 0; i < Dist.Count; i++)
                    {
                        i_订餐份数 += int.Parse(DistCount[i]);

                        FormDisheName += "," + Dist[i].DishesNmae;
                        FormDishesMon += "," + Dist[i].DishesPay;
                        //i_看看的价格 += Dist[i].DishesMon * int.Parse(DistCount[i]);
                        i_商品总价实际价格 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                        i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                    }
                    info.FormDisheName = FormDisheName.Remove(0, 1);
                    info.FormDishesMon = FormDishesMon.Remove(0, 1);
                    i_总价 = i_商品总价实际价格 + i_打包费总价;
                    int i_派送费更多 = 0;
                    if (Mer.Greater > 0 & i_订餐份数 > Mer.Greater)
                    {
                        int djfs = (int)i_订餐份数 - Mer.Greater;
                        double fs = djfs / Mer.HowCount;
                        if (fs == 0) fs = 1;
                        i_派送费更多 = (int)fs * Mer.AddMoney;
                    }
                    i_总价 += Mer.DelFormMon + i_派送费更多;//配送费 
                    #endregion

                    info.FormAllMon = (int)i_总价;
                    //info.FormAllMon = (int)(i_总价);
                    info.LastOper = 1;
                    info.FormPayMon = (int)i_总价;
                    info.FormID = int.Parse(Help.GetSysKey.GetKey("FormKey"));
                    info.DelFormMon = (int)Mer.DelFormMon + i_派送费更多;
                    info.DelPackMon = (int)i_打包费总价;
                    info.LastTime = time;
                    info.FormState = 1;
                    info.FormTime = time;
                    info.IsPay = 2;
                    info.FormBY = "1A02";
                    info.FormPayType = 3;
                    Model.Order_FlowOrganization_T OFO = new Model.Order_FlowOrganization_T();
                    Model.Order_Organization_T OO = base.DBSession.IOrder_Organization_TDAL.GetListBy(u => u.OrgID == info.AccID).First();

                    OFO.OrgBeforeLimit = OO.OrgWaltBalance;
                    OO.OrgWaltBalance -= info.FormAllMon;
                    if (OO.OrgWaltBalance < 0)
                    {
                        result.BS = "-4";
                        result.Msg = "帐号余额不足";
                        return os.StringOfObject(result, RETID);
                    }
                    OFO.OrgRepayAmount = -1 * info.FormAllMon;
                    OFO.OrgAfterLimit = OO.OrgWaltBalance;
                    OFO.MerID = Mer.MerID;
                    OFO.FlowOrgID = int.Parse(Help.GetSysKey.GetKey("OrgFlowKey"));
                    OFO.OrgID = info.AccID;
                    OFO.OrgFlowType = "1A0002";
                    OFO.OrgFormID = info.FormID;
                    OFO.OrgFlowTime = time;
                    OFO.OrgFlowOper = 1;
                    OFO.Flat = 0;
                    if (base.DBSession.IOrder_Organization_TDAL.Modify(OO) > 0)
                    {
                        base.Add(info);

                        #region 菜品更新
                        SaleList = base.DBSession.IOrder_Sales_TDAL.GetListBy(u => u.SalesDate == day & u.SheID == SheLve.SheID & u.SheState == 1);
                        for (int i = 0; i < DishIDs.Length; i++)
                        {
                            Model.Order_Sales_T tm = (from m in SaleList where m.DishesID == DishIDs[i] select m).ToList().First();
                            tm.HaveNub -= int.Parse(DistCount[i]);
                            base.DBSession.IOrder_Sales_TDAL.Modify(tm);
                        }
                        #endregion

                        base.DBSession.IOrder_FlowOrganization_TDAL.Add(OFO);

                        for (int i = 0; i < DishIDs.Length; i++)
                        {
                            string id = DishIDs[i];
                            Model.Order_Dishes_T odt = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.DishesID == id).First();
                            odt.DishesVol += int.Parse(DistCount[i]);
                            base.DBSession.IOrder_Dishes_TDAL.Modify(odt);
                            Mer.SalesCount += int.Parse(DistCount[i]);
                        }
                        base.DBSession.IOrder_Mer_TDAL.Modify(Mer);
                        result.BS = "1";
                        result.Msg = "下单成功";
                        base.DBSession.IOrder_FormLogDAL.Add(new Model.Order_FormLog() { FormId = info.FormID, FormStat = "1A02", OpearDateTime = info.FormTime, OperaId = 0, OperaType = 1 });

                        //Help.ALL_DataV.PushQueue.Enqueue(info);
                    }
                    else
                    {
                        result.BS = "0";
                        result.Msg = "下单不成功";
                    }

                    #endregion
                }
                else
                {
                    result.BS = "-19";
                    result.Msg = "订单类型错误";
                }
            }
            catch (DbEntityValidationException dbex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = dbex.EntityValidationErrors;
                foreach (DbEntityValidationResult result1 in validationResult)
                {
                    ICollection<DbValidationError> validationError = result1.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                //Console.WriteLine(errors.ToString());
                WriteLog.WriteW("AddOrder_OperationFlow异常：" + errors.ToString());

                result.BS = "-99";
                result.Msg = "系统异常";
            }
            catch (DbUpdateException ex)
            {
                WriteLog.WriteW("下订单信息失败DbUpdateException：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("普通用户下订单信息失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            #endregion

            return os.StringOfObject(result, RETID);
        }

        public string BookOrder2(string Data, string PayID, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            #region 执行操作
            try
            {
                WriteLog.WriteW("下订单" + Data);
                Model.Order_Form_T info = ParseClass<Model.Order_Form_T>.StrDeserialize(Data, RETID);

                if (info.Type == "200001")
                {
                    #region 普通用户订单
                    string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                    int day = int.Parse(time.Substring(0, 8));
                    int ti = int.Parse(time.Substring(8, 4));
                    string[] CarID = info.FormCarID.Split(',');
                    string[] DistCount = info.FormDishesNun.Split(',');
                    for (int i = 0; i < DistCount.Length; i++)
                    {
                        if (DistCount[i] == "0")
                        {
                            result.BS = "-21";
                            result.Msg = "菜品数量不能为0";
                            return os.StringOfObject(result, RETID);
                        }
                    }

                    #region 检测钱包是否能用
                    switch (info.FormPayType)
                    {
                        case 1:
                            #region 钱包
                            Model.Order_UserWalt_T UserWalt = new Model.Order_UserWalt_T();
                            try
                            {
                                int z = int.Parse(PayID);
                                UserWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                            }
                            catch (Exception)
                            {
                                result.BS = "-99";
                                result.Msg = "钱包数据异常";
                                return os.StringOfObject(result, RETID);
                            }
                            string str_depID = base.DBSession.IView_UserDAL.GetListBy(u => u.AccID == info.AccID).First().DepID;
                            if (str_depID.Trim() == "")
                            {
                                result.BS = "-6";
                                result.Msg = "用户没有使用此钱包的权限";
                                return os.StringOfObject(result, RETID);
                            }
                            Model.Order_Walt_T orderWalt = new Model.Order_Walt_T();
                            string WID = UserWalt.WaltID.ToString();
                            orderWalt = base.DBSession.IOrder_Walt_TDAL.GetListBy(u => u.WaltID == WID).First();
                            string[] DepList = orderWalt.WaltDep.Split(',');
                            bool jg = true;
                            foreach (var item in DepList)
                            {
                                if (item == str_depID.Substring(0, item.Length))
                                {
                                    jg = false;
                                    break;
                                }
                            }
                            if (jg)
                            {
                                result.BS = "-7";
                                result.Msg = "用户没有使用此钱包的权限";
                                return os.StringOfObject(result, RETID);
                            }
                            if (!orderWalt.WaltMer.Contains(info.FormMerID))
                            {
                                result.BS = "-8";
                                result.Msg = "该商户不能使用此钱包";
                                return os.StringOfObject(result, RETID);
                            }

                            break;
                        #endregion
                        case 2:
                            #region 第三方(微信支付)
                            Model.Order_Pay_T OrderPay;
                            try
                            {
                                OrderPay = base.DBSession.IOrder_Pay_TDAL.GetListBy(u => u.PayID == PayID).First();
                                if (OrderPay.PayOpen != 2 & OrderPay.PayOpen != 3)
                                {
                                    result.BS = "-9";
                                    result.Msg = "用户没有使用此钱包的权限";
                                    return os.StringOfObject(result, RETID);
                                }
                            }
                            catch (Exception)
                            {
                                result.BS = "-99";
                                result.Msg = "钱包数据异常";
                                return os.StringOfObject(result, RETID);
                            }
                            #endregion
                            break;
                        default:
                            break;
                    }
                    #endregion                                        
                    info.FormID = int.Parse(Help.GetSysKey.GetKey("FormKey"));
                    info.FormMerID = "0";
                    info.IsEva = 0;
                    info.LastOper = 0;
                    info.LastTime = time;
                    info.FormState = 1;
                    info.FormTime = time;
                    info.FormBY = "1A02";
                    info.LastOper = 1;
                    if (info.IsTake == 2)
                    {
                        //info.FormPayMon = info.FormPayMon - info.DelFormMon;
                        info.DelFormMon = 0;
                    }
                    switch (info.FormPayType)
                    {
                        case 2:
                            info.IsPay = 0;
                            result.rows = info.FormID + "|" + info.FormPayMon;
                            break;
                        default:
                            info.IsPay = 0;
                            result.rows = info.FormID + "|" + info.FormPayMon;
                            result.total = 1;
                            break;
                    }
                    base.Add(info);

                    #region 购物车更新
                    List<Model.Order_ShoppingCar_T> ShoppingCarList = base.DBSession.IOrder_ShoppingCar_TDAL.GetListBy(u => u.UserID == info.AccID);
                    for (int i = 0; i < CarID.Length; i++)
                    {
                        Model.Order_ShoppingCar_T tm = (from m in ShoppingCarList where m.CarID == CarID[i] select m).ToList().First();
                        base.DBSession.IOrder_ShoppingCar_TDAL.Del(tm);
                    }
                    #endregion

                    if (info.FormPayType != 2)
                    {
                        Model.Order_UserWalt_T USerWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == info.AccID).First();
                        Model.Order_FlowMon_T OFM = new Model.Order_FlowMon_T();
                        OFM.FlowMonID = Help.GetSysKey.GetKey("FlowMonKey");
                        OFM.AccID = info.AccID;
                        OFM.WaltFlowType = "1A0009";
                        OFM.WaltID = PayID;
                        OFM.WaltNowNub = USerWalt.WaltNowNub;
                        OFM.WaltHaveNub = USerWalt.WaltNowNub;
                        OFM.WaltEndNub = USerWalt.WaltNowNub;
                        OFM.WaltFlowTime = time;
                        OFM.WaltFlowOper = 1;
                        OFM.OrdrID = info.FormID;
                        base.DBSession.IOrder_FlowMon_TDAL.Add(OFM);
                    }
                    result.BS = "1";
                    result.Msg = "下单成功";

                    //Help.ALL_DataV.PushQueue.Enqueue(info);
                    return os.StringOfObject(result, RETID);
                    #endregion
                }
                else
                {
                    result.BS = "-19";
                    result.Msg = "订单类型错误";
                }
            }
            catch (DbEntityValidationException dbex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = dbex.EntityValidationErrors;
                foreach (DbEntityValidationResult result1 in validationResult)
                {
                    ICollection<DbValidationError> validationError = result1.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                //Console.WriteLine(errors.ToString());
                WriteLog.WriteW("AddOrder_OperationFlow异常：" + errors.ToString());

                result.BS = "-99";
                result.Msg = "系统异常";
            }
            catch (DbUpdateException ex)
            {
                WriteLog.WriteW("下订单信息失败DbUpdateException：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("普通用户下订单信息失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统异常";
            }
            #endregion

            return os.StringOfObject(result, RETID);
        }

        #region 单独付款功能
        public string singlePay(int FormID, int FormPayType, string PayID, string YZM, int RETID)
        {

            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            Model.Order_Form_T of = new Model.Order_Form_T();
            of = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormID == FormID).First();

            #region 检测钱包是否能用
            switch (FormPayType)
            {
                case 1:
                    #region 钱包
                    Model.Order_UserWalt_T UserWalt = new Model.Order_UserWalt_T();
                    try
                    {
                        int z = int.Parse(PayID);
                        UserWalt = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == of.AccID).First();
                    }
                    catch (Exception)
                    {
                        result.BS = "-99";
                        result.Msg = "钱包数据异常";
                        return os.StringOfObject(result, RETID);
                    }
                    string str_depID = base.DBSession.IView_UserDAL.GetListBy(u => u.AccID == of.AccID).First().DepID;
                    if (str_depID.Trim() == "")
                    {
                        result.BS = "-6";
                        result.Msg = "用户没有使用此钱包的权限";
                        return os.StringOfObject(result, RETID);
                    }
                    Model.Order_Walt_T orderWalt = new Model.Order_Walt_T();
                    string WID = UserWalt.WaltID.ToString();
                    orderWalt = base.DBSession.IOrder_Walt_TDAL.GetListBy(u => u.WaltID == WID).First();
                    string[] DepList = orderWalt.WaltDep.Split(',');
                    bool jg = true;
                    foreach (var item in DepList)
                    {
                        if (item == str_depID.Substring(0, item.Length))
                        {
                            jg = false;
                            break;
                        }
                    }
                    if (jg)
                    {
                        result.BS = "-7";
                        result.Msg = "用户没有使用此钱包的权限";
                        return os.StringOfObject(result, RETID);
                    }
                    if (!orderWalt.WaltMer.Contains(of.FormMerID))
                    {
                        result.BS = "-8";
                        result.Msg = "该商户不能使用此钱包";
                        return os.StringOfObject(result, RETID);
                    }

                    break;
                #endregion
                case 2:
                    #region 第三方
                    Model.Order_Pay_T OrderPay;
                    try
                    {

                        OrderPay = base.DBSession.IOrder_Pay_TDAL.GetListBy(u => u.PayID == PayID).First();
                        if (OrderPay.PayOpen != 2 & OrderPay.PayOpen != 3)
                        {
                            result.BS = "-9";
                            result.Msg = "用户没有使用此钱包的权限";
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    catch (Exception)
                    {
                        result.BS = "-99";
                        result.Msg = "钱包数据异常";
                        return os.StringOfObject(result, RETID);
                    }
                    #endregion
                    break;
                default:
                    break;
            }
            #endregion
            #region MyRegion
            Model.Order_UserWalt_T Uw = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == PayID & u.AccID == of.AccID).First();
            Model.Order_FlowMon_T OFM = new Model.Order_FlowMon_T();
            OFM.FlowMonID = Help.GetSysKey.GetKey("FlowMonKey");
            OFM.AccID = of.AccID;
            OFM.WaltFlowType = "1A0002";
            OFM.WaltID = PayID;
            OFM.WaltNowNub = Uw.WaltNowNub;
            OFM.WaltHaveNub = -1 * (int)of.FormPayMon;
            OFM.WaltEndNub = Uw.WaltNowNub - (int)of.FormPayMon;
            OFM.WaltFlowTime = DateTime.Now.ToString("yyyyMMddHHmmss");
            OFM.WaltFlowOper = 1;
            OFM.OrdrID = of.FormID;
            base.DBSession.IOrder_FlowMon_TDAL.Add(OFM);//新增流水

            Uw.WaltNowNub = Uw.WaltNowNub - (int)of.FormPayMon;

            base.DBSession.IOrder_UserWalt_TDAL.Modify(Uw);//扣款
            of.IsPay = 1;
            of.FormPayType = FormPayType;
            base.DBSession.IOrder_Form_TDAL.Modify(of);
            result.BS = "1";
            result.Msg = "付款成功";



            Help.ALL_DataV.PushQueue.Enqueue(of);
            return os.StringOfObject(result, RETID);
            #endregion
        }
        #endregion

        #region 获取用户订单列表
        /// <summary>
        /// 获取所有订单列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="OpenId">用户微信ID</param>
        /// <param name="type">0：个人 1：企业</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetOrder_Form_User(int pageIndex, int pageSize, string OpenId, int type, string YZM, int RETID)
        {

            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                List<Model.View_Order_Form> ls = new List<Model.View_Order_Form>();
                string ty = type == 0 ? "200001" : "200002";
                ls = base.DBSession.IView_Order_FormDAL.GetListBy("SELECT * FROM  View_Order_Form where FormState=1 and OpenId='" + OpenId + "' and Type='" + ty + "' order by FormID desc");
                if (ls != null & ls.Count > 0)
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.rows = ls.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                    result.total = ls.Count;
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW(" 获取商品分类信息列表失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }

        }
        #endregion

        #region 修改订单状态:
        /// <summary>
        /// 把订单状态改为提交状态2
        /// </summary>
        /// <param name="FormID">订单ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string updFormBY(int FormID, string Flowform, string YZM, int RETID)
        {
            try
            {

                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion 
                Model.Order_Form_T info = new Model.Order_Form_T();
                info = base.GetListBy(u => u.FormID == FormID & u.FormState == 1).First();
                if (info.IsPay == 2)
                {
                    result.BS = "1";
                    result.Msg = "支付成功";
                    return os.StringOfObject(result, RETID);
                }
                string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                string[] DishIDs = info.FormDishesID.Split(',');
                string[] DistCount = info.FormDishesNun.Split(',');
                List<Model.Order_Dishes_T> Dist = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => DishIDs.Contains(u.DishesID));
                double i_商品总价 = 0, i_打包费总价 = 0, i_消费平台积分 = 0, i_消费商户积分 = 0;
                string FormDisheName = "", FormDishesMon = "", FornDishesInt = "";
                int jf_平台 = 0, jf_商户 = 0;
                Model.Order_Key_T Key = base.DBSession.IOrder_Key_TDAL.GetListBy(u => u.ComOpen == u.ComOpen).First();
                List<Model.Order_Int_T> OI_平台list = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == "0");
                List<Model.Order_Int_T> OI_商户list = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID);
                int i_总份数 = 0;
                for (int i = 0; i < Dist.Count; i++)
                {
                    i_总份数 += int.Parse(DistCount[i]);
                    #region MyRegion
                    FormDisheName += "," + Dist[i].DishesNmae;
                    if (Dist[i].DishesIsInt == 0)
                    {
                        FormDishesMon += "," + Dist[i].DishesPay;
                        FornDishesInt += ",0";
                    }
                    else
                    {
                        FormDishesMon += ",0";
                        FornDishesInt += "," + Dist[i].DishesPay;
                    }

                    if (Dist[i].DishesIsInt == 0)
                    {
                        i_商品总价 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                        i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                        #region 积分
                        switch (Dist[i].DishesEnableInt)
                        {
                            case 1:
                                if (OI_平台list.Count > 0)
                                {
                                    switch (OI_平台list[0].IntUn)
                                    {
                                        case 1:
                                            jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe;
                                            break;
                                        case 2:
                                            jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe / 10;
                                            break;
                                        default:
                                            jf_平台 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_平台list[0].IntChe / 100;
                                            break;
                                    }
                                }
                                break;
                            case 2:
                                if (OI_商户list.Count > 0)
                                {
                                    switch (OI_商户list[0].IntUn)
                                    {
                                        case 1:
                                            jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe;
                                            break;
                                        case 2:
                                            jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe / 10;
                                            break;
                                        default:
                                            jf_商户 += (int)(Dist[i].DishesPay * int.Parse(DistCount[i])) * OI_商户list[0].IntChe / 100;
                                            break;
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                        #endregion
                    }
                    else
                    {
                        if (Dist[i].DishesIsInt == 1)
                        {
                            i_消费平台积分 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                            i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                        }
                        else
                        {
                            i_消费商户积分 += Dist[i].DishesPay * int.Parse(DistCount[i]);
                            i_打包费总价 += Dist[i].DelPackMon * int.Parse(DistCount[i]);
                        }
                    }
                    #endregion
                }
                Model.Order_Int_T Oi_平台 = new Model.Order_Int_T(), Oi_商户 = new Model.Order_Int_T();
                if (i_消费平台积分 > 0)
                {
                    #region i_消费平台积分
                    Oi_平台 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == "0").First();
                    List<Model.Order_UserInt_T> PTList = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.AccID == info.AccID & u.IntID == Oi_平台.IntID);
                    Model.Order_FlowInt_T FM = new Model.Order_FlowInt_T();
                    FM.FlowIntID = Help.GetSysKey.GetKey("FlowIntKey");
                    FM.IntNowNub = PTList[0].IntNowNub;
                    FM.IntEndNub = PTList[0].IntNowNub - (int)i_消费平台积分;
                    PTList[0].IntNowNub = PTList[0].IntNowNub - (int)i_消费平台积分;
                    PTList[0].IntAllNub = PTList[0].IntAllNub + (int)i_消费平台积分;
                    PTList[0].LastUpTime = time;
                    PTList[0].LastUpFlow = FM.FlowIntID;
                    base.DBSession.IOrder_UserInt_TDAL.Modify(PTList[0]);

                    FM.AccID = info.AccID;

                    FM.IntFlowType = "1B0002";
                    FM.IntID = Oi_平台.IntID;
                    FM.OrdrID = info.FormID;
                    FM.IntHaveNub = -1 * (int)i_消费平台积分;
                    FM.IntFlowTime = time;
                    FM.IntFlowOper = 0;
                    base.DBSession.IOrder_FlowInt_TDAL.Add(FM);
                    #endregion
                }
                if (i_消费商户积分 > 0)
                {
                    #region MyRegion
                    Oi_商户 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                    List<Model.Order_UserInt_T> PTList = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.AccID == info.AccID & u.IntID == Oi_商户.IntID);
                    Model.Order_FlowInt_T FM = new Model.Order_FlowInt_T();
                    FM.FlowIntID = Help.GetSysKey.GetKey("FlowIntKey");
                    FM.IntNowNub = PTList[0].IntNowNub;
                    FM.IntEndNub = PTList[0].IntNowNub - (int)i_消费商户积分;
                    PTList[0].IntNowNub = PTList[0].IntNowNub - (int)i_消费商户积分;
                    PTList[0].IntAllNub = PTList[0].IntAllNub + (int)i_消费商户积分;
                    PTList[0].LastUpTime = time;
                    PTList[0].LastUpFlow = FM.FlowIntID;
                    try
                    {

                        base.DBSession.IOrder_UserInt_TDAL.Modify(PTList[0]);
                    }
                    catch (Exception)
                    {

                    }

                    FM.AccID = info.AccID;

                    FM.IntFlowType = "1B0002";
                    FM.IntID = Oi_商户.IntID;
                    FM.OrdrID = info.FormID;
                    FM.IntHaveNub = -1 * (int)i_消费商户积分;
                    FM.IntFlowTime = time;
                    FM.IntFlowOper = 0;

                    base.DBSession.IOrder_FlowInt_TDAL.Add(FM);
                    #endregion
                }
                Model.Order_Mer_T Mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                if (info.FormPayType == 1)
                {
                    #region 如果是钱包支付
                    for (int i = 0; i < DishIDs.Length; i++)
                    {
                        string id = DishIDs[i];
                        Model.Order_Dishes_T odt = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.DishesID == id).First();
                        odt.DishesVol += int.Parse(DistCount[i]);
                        try
                        {

                            base.DBSession.IOrder_Dishes_TDAL.Modify(odt);
                        }
                        catch (Exception)
                        {

                        }
                        //Mer.SalesCount += int.Parse(DistCount[i]);
                    }
                    // base.DBSession.IOrder_Mer_TDAL.Modify(Mer);
                    if (info.FormPayMon > 0)
                    {
                        //int Wid = int.Parse(PayID);
                        #region MyRegion
                        Model.Order_FlowMon_T OFT = base.DBSession.IOrder_FlowMon_TDAL.GetListBy(u => u.OrdrID == info.FormID).Last();
                        Model.Order_UserWalt_T Uw = base.DBSession.IOrder_UserWalt_TDAL.GetListBy(u => u.WaltID == OFT.WaltID & u.AccID == info.AccID).First();
                        Model.Order_FlowMon_T OFM = new Model.Order_FlowMon_T();
                        OFM.FlowMonID = Help.GetSysKey.GetKey("FlowMonKey");
                        OFM.AccID = info.AccID;
                        OFM.WaltFlowType = "1A0002";
                        OFM.WaltID = OFT.PayID;
                        OFM.WaltNowNub = Uw.WaltNowNub;
                        OFM.WaltHaveNub = -1 * info.FormPayMon;
                        OFM.WaltEndNub = Uw.WaltNowNub - info.FormPayMon;
                        OFM.WaltFlowTime = time;
                        OFM.WaltFlowOper = 1;
                        OFM.OrdrID = info.FormID;
                        OFM.WaltID = OFT.WaltID;
                        base.DBSession.IOrder_FlowMon_TDAL.Add(OFM);

                        Uw.WaltNowNub = Uw.WaltNowNub - info.FormPayMon;

                        base.DBSession.IOrder_UserWalt_TDAL.Modify(Uw);
                        #endregion

                    }
                    #endregion
                }
                if (info.FormPayType == 2)
                {
                    Model.Order_FlowPay_T of = new Model.Order_FlowPay_T();
                    of.AccID = info.AccID;
                    of.FlowPayID = GetSysKey.GetKey("FlowPayKey");
                    of.OrdrID = info.FormID.ToString();
                    of.PayFlowOper = 0;
                    of.PayFlowTime = time;
                    of.PayFlowType = "1C0004";
                    of.PayHaveNub = -1 * info.FormPayMon;
                    of.PayID = "wxzf";
                    of.PayOherID = Flowform;
                    string sqlflow = "select * from Order_FlowPay_T where PayOherID='" + Flowform + "'";
                    List<Model.Order_FlowPay_T> listflow = base.DBSession.IOrder_FlowPay_TDAL.GetListBy(sqlflow);
                    if (listflow.Count == 0)//没记录则插入流水
                    {
                        base.DBSession.IOrder_FlowPay_TDAL.Add(of);
                    }
                }
                if (jf_平台 > 0)
                {
                    #region MyRegion
                    Model.Order_FlowInt_T FM = new Model.Order_FlowInt_T();
                    FM.FlowIntID = Help.GetSysKey.GetKey("FlowIntKey");
                    List<Model.Order_UserInt_T> PTList = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.AccID == info.AccID & u.IntID == "0");

                    FM.IntID = Oi_平台.IntID;
                    if (PTList.Count > 0)
                    {
                        FM.IntNowNub = PTList[0].IntNowNub;
                        FM.IntEndNub = PTList[0].IntNowNub + jf_平台;
                        PTList[0].IntNowNub = PTList[0].IntNowNub + jf_平台;
                        PTList[0].IntConNub = PTList[0].IntConNub + jf_平台;
                        PTList[0].LastUpTime = time;
                        PTList[0].LastUpFlow = FM.FlowIntID;
                        base.DBSession.IOrder_UserInt_TDAL.Modify(PTList[0]);
                    }
                    else
                    {
                        Model.Order_UserInt_T pt = new Model.Order_UserInt_T();
                        pt.AccID = info.AccID;
                        pt.IntConNub = jf_平台;
                        pt.IntID = "0";
                        pt.IntNowNub = jf_平台;
                        pt.IntConNub = jf_平台;
                        pt.LastUpTime = time;
                        pt.LastUpFlow = FM.FlowIntID;
                        FM.IntNowNub = jf_平台;
                        FM.IntEndNub = jf_平台;
                        //PTList[0].IntNowNub = jf_平台;
                        //PTList[0].IntConNub = jf_平台;
                        base.DBSession.IOrder_UserInt_TDAL.Add(pt);
                    }
                    FM.AccID = info.AccID;

                    FM.IntFlowType = "1B0001";
                    FM.IntID = "0";
                    FM.OrdrID = info.FormID;
                    FM.IntHaveNub = jf_平台;
                    FM.IntFlowTime = time;
                    FM.IntFlowOper = 0;
                    base.DBSession.IOrder_FlowInt_TDAL.Add(FM);
                    #endregion
                }
                if (jf_商户 > 0)
                {
                    #region MyRegion
                    Model.Order_FlowInt_T FM = new Model.Order_FlowInt_T();
                    FM.FlowIntID = Help.GetSysKey.GetKey("FlowIntKey");
                    Oi_商户 = base.DBSession.IOrder_Int_TDAL.GetListBy(u => u.MerID == info.FormMerID).First();
                    List<Model.Order_UserInt_T> PTList = base.DBSession.IOrder_UserInt_TDAL.GetListBy(u => u.AccID == info.AccID & u.IntID == Oi_商户.IntID);

                    FM.IntID = Oi_商户.IntID;

                    if (PTList.Count > 0)
                    {
                        FM.IntNowNub = PTList[0].IntNowNub;
                        FM.IntEndNub = PTList[0].IntNowNub + jf_商户;
                        PTList[0].IntNowNub = PTList[0].IntNowNub + jf_商户;
                        PTList[0].IntConNub = PTList[0].IntConNub + jf_商户;
                        PTList[0].LastUpTime = time;
                        PTList[0].LastUpFlow = FM.FlowIntID;
                        base.DBSession.IOrder_UserInt_TDAL.Modify(PTList[0]);

                    }
                    else
                    {
                        Model.Order_UserInt_T pt = new Model.Order_UserInt_T();
                        pt.AccID = info.AccID;
                        pt.IntConNub = jf_商户;
                        pt.IntID = Oi_商户.IntID;
                        pt.IntNowNub = jf_商户;
                        pt.IntConNub = jf_商户;
                        pt.LastUpTime = time;
                        pt.LastUpFlow = FM.FlowIntID;
                        FM.IntNowNub = jf_商户;
                        FM.IntEndNub = jf_商户;
                        // PTList[0].IntNowNub = jf_商户;
                        // PTList[0].IntConNub = jf_商户;
                        base.DBSession.IOrder_UserInt_TDAL.Add(pt);
                    }
                    FM.AccID = info.AccID;
                    FM.IntFlowType = "1B0001";
                    FM.OrdrID = info.FormID;
                    FM.IntHaveNub = jf_商户;
                    FM.IntFlowTime = time;
                    FM.IntFlowOper = 0;

                    base.DBSession.IOrder_FlowInt_TDAL.Add(FM);
                    #endregion
                }
                if (info != null)
                {
                    Mer.SalesCount += i_总份数;

                    info.FormBY = "1A02";
                    info.IsPay = 2;
                    base.Modify(info);
                    result.BS = "1";
                    result.Msg = "支付成功";
                    base.DBSession.IOrder_FormLogDAL.Add(new Model.Order_FormLog() { FormId = info.FormID, FormStat = "1A02", OpearDateTime = info.FormTime, OperaId = 0, OperaType = 1 });
                    base.DBSession.IOrder_Mer_TDAL.Modify(Mer);
                    Help.ALL_DataV.PushQueue.Enqueue(info);
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "查询不到数据";
                }

                return os.StringOfObject(result, RETID);
            }
            catch (DbEntityValidationException dbex)
            {
                StringBuilder errors = new StringBuilder();
                IEnumerable<DbEntityValidationResult> validationResult = dbex.EntityValidationErrors;
                foreach (DbEntityValidationResult result in validationResult)
                {
                    ICollection<DbValidationError> validationError = result.ValidationErrors;
                    foreach (DbValidationError err in validationError)
                    {
                        errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                    }
                }
                WriteLog.WriteW("updFormBY异常FormID" + FormID + " Flowform:" + Flowform + "|" + errors.ToString());
                result.BS = "-99";
                result.Msg = "DbEntityValidationException错误！";
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW(" 获取数据失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }


        }

        #endregion

        #region 查询订单是否已付款:
        /// <summary>
        /// 查询订单是否已付款:
        /// </summary>
        /// <param name="FormID">订单ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string FeatchIspy(int FormID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                Model.Order_Form_T formby = new Model.Order_Form_T();
                formby = base.GetListBy(u => u.FormID == FormID & u.FormState == 1).First();
                if (formby != null)
                {
                    if (formby.IsPay == 2 || formby.IsPay == 4)
                    {
                        result.BS = "1";
                        result.Msg = "该订单已支付";
                    }
                    else
                    {
                        result.BS = "0";
                        result.Msg = "该订单未支付";
                    }
                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW(" 获取数据失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }
        }
        #endregion

        #region 用户付款成功后更新订单支付状态
        /// <summary>
        /// 用户付款成功后更新订单支付状态
        /// </summary>
        /// <param name="FormID">订单ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string UpdateFormIsPay(int FormID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                int ret = 0;
                List<Model.Order_Form_T> formlist = base.GetListBy(u => u.FormID == FormID & u.FormState == 1).ToList();
                if (formlist != null && formlist.Count() > 0)
                {
                    Model.Order_Form_T tem = formlist.First();
                    tem.IsPay = 2;
                    ret = base.Modify(tem);
                    if (ret > 0)
                    {
                        result.BS = "1";
                        result.Msg = "该订单已支付";
                    }
                    else
                    {
                        result.BS = "0";
                        result.Msg = "该订单未支付";
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW(" 获取数据失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
            }
            return os.StringOfObject(result, RETID);
        }
        #endregion

        /// <summary>
        /// 根所订单号查询订单详情
        /// </summary>
        /// <param name="FormID">订单ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetFormByID(int FormID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion

                List<Model.View_Order_Form> oftList = base.DBSession.IView_Order_FormDAL.GetListBy("SELECT *  FROM  View_Order_Form where FormID=" + FormID);
                if (oftList.Count <= 0)
                {
                    result.BS = "0";
                    result.Msg = "查不到数据";
                }
                else
                {
                    result.BS = "1";
                    result.Msg = "查询成功";
                    result.total = 1;
                    result.rows = oftList;
                }
            }
            catch (Exception e)
            {
                result.BS = "-99";
                result.Msg = "系统异常";
                WriteLog.WriteW("GetFormByID   " + e.Message);
            }
            return os.StringOfObject(result, RETID);

        }

        #region 根据微信OpenID获取该派送人员的全部订单
        /// <summary>
        /// 根据微信OpenID获取该派送人员的全部订单
        /// </summary>
        /// <param name="OpenID">微信的唯一ID值（该值必须是在系统中登记）</param>
        /// <param name="FormID">订单编号（为空则忽略）</param>
        /// <param name="GetType">获取模块（1：获取今天的全部订单信息 2：获取历史订单信息），当查询今天的全部订单信息时，下面入参Sdate和Edate无效。</param>
        /// <param name="pageIndex">页数</param>
        /// <param name="pageSize">没页大小</param>
        /// <param name="Sdate">开始时间 yyyyMMdd ,含。</param>
        /// <param name="Edate">结束时间 yyyyMMdd ,含。</param>
        /// <param name="ConID">状态类型（0：查询全部、其他则传状态码ID）</param>
        /// <param name="YZM">验证码默认 缺省</param>
        /// <param name="RETID">返回数据格式（1：json）</param>
        /// <returns></returns>
        public string GetOrder_OpenIDSendList(string OpenID, string FormID, string GetType, int pageIndex, int pageSize, string Sdate, string Edate, string ConID, string YZM, int RETID)
        {
            #region 匹配验证码
            //WriteLog.WriteW("获取该派送人员的全部订单失败：" + Help.ALL_DataV.YZM + "yzm:" + YZM);
            //if (!string.Equals(YZM, Help.ALL_DataV.YZM))
            //{
            //    WriteLog.WriteW("获取该派送人员的全部订单失败11：" + Help.ALL_DataV.YZM + "yzm:" + YZM);
            //    result.BS = "-88";
            //    result.Msg = "验证码错误！";
            //    return os.StringOfObject(result, RETID);
            //}
            #endregion
            string OpenIDName = "";//送餐员名字
            string Time = "";//时间条件
            string Cid = "";//订单状态条件
            string formid = "";//订单编号条件
            string msg = "";
            string bs = "";
            int TakerID;
            string Fid = "";
            string name = "";
            #region 执行操作
            try
            {
                List<Model.Order_Form_T> List_Ofmt_sb = new List<Model.Order_Form_T>();//装入筛选值
                List<Model.Order_Taker_T> List_mott = base.DBSession.IOrder_Taker_TDAL.GetListBy(u => u.TakerOpenID == OpenID && u.TakerState == 1 && u.TakerRole == 2);//查找匹配的微信标识

                List<Model.Order_Form_T> List_Ofmt = new List<Model.Order_Form_T>();//初始化订单信息表
                TakerID = List_mott[0].TakerID;//送餐员系统ID
                name = List_mott[0].TakerName;////送餐员系统名字
                //List<Model.Order_Send_T> List_Ost = base.DBSession.IOrder_Send_TDAL.GetListBy(u => u.TakerID == TakerID && u.SendState == 1);//订单派送信息表
                string takerids = String.Join(",", List_mott.Select(u => u.TakerID));
                List<Model.Order_Send_T> List_Ost = base.DBSession.IOrder_Send_TDAL.GetListBy("select * from Order_Send_T where SendState=1 and TakerID in(" + takerids + ")");//订单派送信息表
                if (List_mott.Count > 0 && List_Ost.Count > 0)//说明找到匹配的标识
                {
                    OpenIDName = List_mott[0].TakerName;//送餐员系统名字
                    #region 封装时间条件
                    if (GetType == "1")//获取今天的全部订单信息
                    {
                        Time = " LastTime like'" + DateTime.Now.ToString("yyyyMMdd") + "%' and ";//当天时间
                    }
                    else if (GetType == "2")
                    {
                        Time = " LastTime>='" + Sdate + "000000" + "'and LastTime<='" + Edate + "235959" + "' and ";//历史时间
                        //Time = " FormTime like'" + Sdate + "%'and FormTime like'" + Edate + "%' and ";//历史时间
                    }
                    #endregion
                    #region 封装订单状态条件


                    if (ConID == "0")//查询全部
                    {
                        Cid = " ";
                    }
                    else//其他则传状态码ID
                    {

                        Cid = " FormBY='" + ConID + "' and ";


                    }
                    #endregion
                    #region 封装订单编号条件

                    if (!string.IsNullOrEmpty(FormID))//订单编号不为空的时候，根据订单ID查询订单 FormID != null || FormID != ""
                    {
                        //int nFormID = Convert.ToInt32(FormID);//将订单号转成int类型
                        List_Ost = base.DBSession.IOrder_Send_TDAL.GetListBy(u => u.TakerID == TakerID && u.SendState == 1 && u.FormID == FormID);
                        Fid = List_Ost[0].FormID;
                        formid = " FormID='" + Fid + "'and ";

                        List_Ofmt = base.DBSession.IOrder_Form_TDAL.GetListBy("select * from Order_Form_T "
                        + "where " + formid + Time + Cid + " FormState=1 order by FormTime desc");//查询有效的订餐信息
                        List_Ofmt_sb.AddRange(List_Ofmt);
                    }
                    else
                    {
                        //formid = " ";

                        //List<Model.Order_Form_T> List_Ofmt_sb = new List<Model.Order_Form_T>();//初始化订单信息表
                        for (int n = 0; n < List_Ost.Count; n++)
                        {
                            formid = " FormID='" + List_Ost[n].FormID + "'and ";
                            List_Ofmt = base.DBSession.IOrder_Form_TDAL.GetListBy("select * from Order_Form_T "
                       + "where " + formid + Time + Cid + " FormState=1 order by FormTime desc");//查询有效的订餐信息
                            List_Ofmt_sb.AddRange(List_Ofmt);
                        }

                    }
                    #endregion


                    //List_Ofmt = base.DBSession.IOrder_Form_TDAL.GetListBy("select * from Order_Form_T "
                    //+ "where " + formid + Time + Cid + " FormState=1 order by FormTime desc");//查询有效的订餐信息
                    //for (int i = 0; i < List_Ofmt.Count; i++)
                    //{
                    //    string FmID = List_Ofmt[i].FormMerID;
                    //    List<Model.Order_Mer_T> List_OMT = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == FmID);//冲商户信息表里获取商户名
                    //    List_Ofmt[i].IntBZ = OpenIDName;
                    //    List_Ofmt[i].FormMerID = List_OMT[0].MerName;
                    //}
                    //“派送员在系统登记的名称”用IntBZ来存放，商户名称用FormMerID来存
                    for (int i = 0; i < List_Ofmt_sb.Count; i++)
                    {
                        string FmID = List_Ofmt_sb[i].FormMerID;
                        List<Model.Order_Mer_T> List_OMT = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == FmID);//冲商户信息表里获取商户名
                        List_Ofmt_sb[i].IntBZ = OpenIDName;
                        List_Ofmt_sb[i].FormMerID = List_OMT[0].MerName;
                    }
                    bs = "1";
                    msg = name + "|" + "获取成功！";
                }
                else if (List_mott.Count > 0)
                {
                    bs = "1";
                    msg = name + "|" + "获取成功！";
                }
                else
                {
                    bs = "-2";
                    msg = "查询失败！";
                }
                result.BS = bs;

                result.Msg = msg;
                if (pageSize == 0)//获取全部数据不分页
                {
                    //result.rows = List_Ofmt;
                    //result.total = List_Ofmt.Count;
                    //return os.StringOfObject(result, RETID);
                    result.rows = List_Ofmt_sb;
                    result.total = List_Ofmt_sb.Count;
                    return os.StringOfObject(result, RETID);

                }
                else
                {
                    //result.rows = List_Ofmt.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                    //result.total = List_Ofmt.Count;
                    //return os.StringOfObject(result, RETID);
                    result.rows = List_Ofmt_sb.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                    result.total = List_Ofmt_sb.Count;
                    return os.StringOfObject(result, RETID);
                }

            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取该派送人员的全部订单失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "获取失败";
                return os.StringOfObject(result, RETID);
            }
            #endregion
        }
        #endregion

        #region 变更订单状态及留言（派送员模式）
        /// <summary>
        /// 变更订单状态及留言
        /// </summary>
        /// <param name="OpenID">微信的唯一ID值（该值必须是在系统中登记）</param>
        /// <param name="FormID">订单编号（为空则忽略）</param>
        /// <param name="ConID">变更为某状态类型（传状态码ID）</param>
        /// <param name="WillTime">预计送达时间（HHmm 时分格式24小时制）</param>
        /// <param name="LY">派送员留言</param>
        /// <param name="YZM">验证码默认 缺省</param>
        /// <param name="RETID">返回数据格式（1：json）</param>
        /// <returns></returns>
        public string UpForm_OpenIDSend(string OpenID, string FormID, string ConID, string WillTime, string LY, string YZM, int RETID)
        {

            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            try
            {
                int TakerID;//关联的送餐员ID
                int bs;
                Help.ComdSqlFactory ap = new ComdSqlFactory();//单条更改数据库
                List<Model.Order_Taker_T> list_MOtk_t = new List<Model.Order_Taker_T>();
                List<Model.Order_FormLog> list_mode_of = new List<Model.Order_FormLog>();
                list_MOtk_t = base.DBSession.IOrder_Taker_TDAL.GetListBy(u => u.TakerOpenID == OpenID && u.TakerState == 1);//根据微信唯一ID获取
                TakerID = list_MOtk_t[0].TakerID;//关联的送餐员ID
                bool updates;
                bool updates1;
                bool updates2;
                if (FormID != null && TakerID != 0)//订单编号（为空则忽略）
                {
                    int fmid = Convert.ToInt32(FormID);
                    string BZ = LY + "; 预计送达时间：" + WillTime;
                    int FormId = fmid;
                    string OperaId = OpenID;
                    string FormStat = ConID;
                    int OperaType = 2;
                    string OpearDateTime = DateTime.Now.ToString("yyyyMMddHHmmss");
                    updates = ap.ExecuteScalar("update Order_Form_T set FormBY='" + ConID + "'where  FormID='" + FormID + "' and FormState=1 ");//更新订单信息表订单状态

                    Model.Order_Form_T formt = base.GetListBy(u => u.FormID == FormId).First();
                    updates1 = ap.ExecuteScalar("update Order_Send_T set TakerID='" + TakerID + "'where FormID='" + FormID + "'and SendState=1");//更新订单派送信息表
                    updates2 = ap.ExecuteScalar("insert into Order_FormLog(FormId,FormStat,OperaId,OperaType,OpearDateTime,BZ) VALUES  ('" + FormId + "','" + FormStat + "','" + TakerID + "','" + OperaType + "','" + OpearDateTime + "','" + BZ + "')");//更新订单信息表         
                    //RETID=1;

                    if (updates == true && updates1 == true && updates2 == true)
                    {
                        WriteLog.WriteW("UpForm_OpenIDSend    更新在订单状态：" + ConID + "订单ID：" + FormID + "支付状态为：" + formt.IsPay);
                        WriteLog.WriteW("更新数据成功！");
                        result.BS = "1";
                        result.Msg = "更新成功！";
                    }
                    else
                    {
                        WriteLog.WriteW(" 更新数据失败！");
                        result.BS = "-11";
                        result.Msg = "更新失败！";
                    }

                }
                return os.StringOfObject(result, RETID);
            }
            catch (Exception ex)
            {
                WriteLog.WriteW(" 获取数据失败：" + ex.Message);
                result.BS = "-99";
                result.Msg = "系统错误！";
                return os.StringOfObject(result, RETID);
            }


            //return OpenID;
        }
        #endregion

        #region 定时清除未支付的订单
        /// <summary>
        /// 定时清除未支付的订单
        /// </summary>
        /// <returns></returns>
        public string ClearForm()
        {
            string now_s = DateTime.Now.AddMinutes(-5).ToString("yyyyMMddHHmmss");
            string sql = "select* from Order_Form_T where IsPay = 0 and SenTime< '" + now_s + "' and FormState = 1";
            // WriteLog.WriteW("查找未支付的订单:" + sql);
            List<Model.Order_Form_T> s = base.GetListBy(sql);
            for (int n = 0; n < s.Count; n++)
            {
                WriteLog.WriteW("找到未支付的订单,订单号:" + s[n].FormID);
                if (s[n].FormPayType == 2)
                {

                    WxPayData req = new WxPayData();
                    req.SetValue("out_trade_no", s[n].FormID);

                    if (WxPayConfig.sfg)
                    {
                        req.SetValue("sub_mch_id", WxPayConfig.SUB_MCHID);//子商户号
                    }
                    //WriteLog.WriteW("找到未支付的订单,订单号:" + s[n].FormID+"初始化查询属性");
                    WxPayData res;
                    try
                    {
                        res = WxPayApi.OrderQuery(req);
                    }
                    catch (Exception ex)
                    {
                        WriteLog.WriteW("找到未支付的订单,订单号:" + s[n].FormID + "向微信查询异常");
                        throw;
                    }

                    WriteLog.WriteW("找到未支付的订单,订单号:" + s[n].FormID + "查询结束");
                    if (res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS")
                    {
                        object o = res.GetValue("transaction_id");
                        if (o != null)
                        {
                            WriteLog.WriteW("清除订单从微信查询订单:" + res.GetValue("transaction_id").ToString());
                            updFormBY(s[n].FormID, res.GetValue("transaction_id").ToString(), Help.ALL_DataV.YZM, 1);
                        }
                        else
                        {
                            WriteLog.WriteW("订单微信查询到订单" + s[n].FormID + "未支付");
                            ReBookOrder(s[n].FormID, "", 3, 1, "", 1);
                        }
                    }
                    else
                    {
                        WriteLog.WriteW("清除订单微信查询不到订单");
                        ReBookOrder(s[n].FormID, "", 3, 1, "", 1);
                    }
                }
                else
                {
                    ReBookOrder(s[n].FormID, "", 3, 1, "", 1);
                }

            }



            return "";
        }
        #endregion

        /// <summary>
        /// 入参订单ID获取比他新的订单数
        /// </summary>
        /// <param name="FormID"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetNewOrderId(int FormID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion
                Model.Order_Form_T of = base.GetListBy(u => u.FormID == FormID).First();
                int to = base.GetListBy(u => u.FormID > FormID & u.FormMerID == of.FormMerID & u.FormState == 1).Count;
                result.BS = "1";
                result.Msg = "查询成功";
                result.total = to;
            }
            catch (Exception e)
            {
                result.BS = "-99";
                result.Msg = "系统异常";
                WriteLog.WriteW("GetNewOrderId   " + e.Message);
            }
            return os.StringOfObject(result, RETID);
        }


        /// <summary>
        /// 入参订单ID获取比他新的订单数
        /// </summary>
        /// <param name="FormID"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetNewOrderIdByPS(int FormID, string YZM, int RETID)
        {
            try
            {
                #region 匹配验证码
                if (YZM != Help.ALL_DataV.YZM)
                {
                    result.BS = "-88";
                    result.Msg = "验证码错误！";
                    return os.StringOfObject(result, RETID);
                }
                #endregion 
                int to = base.GetListBy(u => u.FormID > FormID & u.FormState == 1 & u.FormBY == "1A04").Count;
                result.BS = "1";
                result.Msg = "查询成功";
                result.total = to;
            }
            catch (Exception e)
            {
                result.BS = "-99";
                result.Msg = "系统异常";
                WriteLog.WriteW("GetNewOrderId   " + e.Message);
            }
            return os.StringOfObject(result, RETID);
        }


        #region 确认订单页面获取信息
        /// <summary>
        /// 获取购物车选中的商品
        /// </summary>
        /// <param name="CarID">购物车商品ID</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：JSON；2：XML）</param>
        /// <returns></returns>
        public string GetDishesShoppingCar(string[] CarID, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            List<Model.Order_ShoppingCar_T> mo = new List<Model.Order_ShoppingCar_T>();
            if (CarID.Count() > 0)
            {
                foreach (var item in CarID)
                {
                    string[] CarIDInfo = item.Split(',');
                    foreach (var items in CarIDInfo)
                    {
                        List<Model.Order_ShoppingCar_T> ls = new List<Model.Order_ShoppingCar_T>();
                        ls = base.DBSession.IOrder_ShoppingCar_TDAL.GetListBy(u => u.CarID == items).ToList();
                        mo.AddRange(ls);
                    }
                }
            }
            if (mo != null & mo.Count() > 0)
            {
                result.BS = "1";
                result.Msg = "查询成功";
                result.rows = mo;
                result.total = mo.Count();
            }
            else
            {
                result.BS = "0";
                result.Msg = "查询不到数据";
            }
            return os.StringOfObject(result, RETID);
        }

        #endregion
    }
}
